Skip to content
Advertisement

Is there any way to create mongodb like _id strings without mongodb?

I really like the format of the _ids generated by mongodb. Mostly because I can pull data like the date out of them client side. I’m planning to use another database but still want that type of _id for my document. How can I create these ids without using mongodb?

Thanks!

Advertisement

Answer

Object IDs are usually generated by the client, so any MongoDB driver would have code to generate them.

If you’re looking for JavaScript, here’s some code from the MongoDB Node.js driver:

https://github.com/mongodb/js-bson/blob/1.0-branch/lib/bson/objectid.js

And another, simpler solution:

https://github.com/justaprogrammer/ObjectId.js

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement