Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  147] [ 7]  / answers: 1 / hits: 41706  / 12 Years ago, tue, may 15, 2012, 12:00:00

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!


More From » node.js

 Answers
47

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


[#85577] Monday, May 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
armandoh

Total Points: 208
Total Questions: 94
Total Answers: 112

Location: South Sudan
Member since Sun, Jul 11, 2021
3 Years ago
;