Converting BSON to a Object String (Mongo/Mongoose)

106 views
Skip to first unread message

Lukas Wilkeer

unread,
Dec 16, 2019, 11:11:22 AM12/16/19
to nodejs
Hi folks,

In mongo db, a ObjectId is composed by a random string hash and timestamp, converting do BSON type is an array like [Buffer, something, timestamp]. When saved to DB is converted do a hex string.

Currently I'm stuck on a problem with BSON types.

The current _id doesn't match with retrived id from document, based on that type is converted to a ObjectId, not a literal hex string.

Using methods like, toString and toHexString(on BSON type) doesn't match with current store _id string.


I'm attempted recover the string using _doc methods from a find query, the two methods cited above (toString and toHexString) and (that returns a Buffer) and convert the _id string to a ObjectId that not generate a BSON Type _id.

What to do in that case?


Reply all
Reply to author
Forward
0 new messages