Question

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

As a driver I'm using monk.

Was it helpful?

Solution

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){});

OTHER TIPS

convert to json then to bson I think

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top