How to randomly generate objectid in node js

user1705980 picture user1705980 · Oct 9, 2012 · Viewed 14.1k times · Source

I need to randomly generate objectid in node js.Is there is any way to create.

Answer

Werner Kvalem Vesterås picture Werner Kvalem Vesterås · Oct 9, 2012

If you mean a MongoDB ObjectID, try this:

var ObjectID = require('mongodb').ObjectID;

var objectId = new ObjectID();