Frage

How i can convert string (_id) to BSON object?

As a driver I'm using monk.

War es hilfreich?

Lösung

Monk defines the id and oid (alias) methods for casting to ObjectID:

users.id() // returns new generated ObjectID
users.id('hexstring') // returns ObjectId
users.id(obj) // returns ObjectId

Though it seems capable of working with the string as well:

users.findById('hex representation', function(err, doc){});
users.findById(oid, function(err, doc){});

Andere Tipps

convert to json then to bson I think

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top