Monday, 15 July 2013

mongoose - mongodb: how to automatically generate an id to a newly created object? -


I am creating a new object with Mongoos, how to automatically specify an ID for that object?

This is what I have done so far (see: coffeescript):

  ObjectSchema = new schema ({#some else property ID: {type: Schema.ObjectId , Essential: true}})  

In this way I am creating this:

  obj = new object () # some points obj.save ( (Mistake) -> If the mistake is? Console.log (err) else console.log ("Successfully Saved"))  

which gives me this error:

  Validation Error: Path requires `id`  

Any id fee in your schema No announcement of D, and then save, a _id Otogenerted field in your object.


No comments:

Post a Comment