dimadima dimadima - 1 year ago 127
Node.js Question

How can I generate an ObjectId with mongoose?

I'd like to generate a MongoDB

with Mongoose. Is there a way to access the
constructor from Mongoose?

Answer Source

Yes, you can find the ObjectId constructor on require('mongoose').Types. Here is an example:

var mongoose = require('mongoose');
var id = mongoose.Types.ObjectId();

id is a newly generated ObjectId.

You can read more about the Types object at Mongoose#Types documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download