caminte icon indicating copy to clipboard operation
caminte copied to clipboard

How to retrieve the primary key of a new record using Mongoose adapter?

Open victorldomingues opened this issue 8 years ago • 0 comments

I am using the create method callback to get the primary key "_id", however this return the key is empty (null).

var category = new Category();
    category.create({
        name: "My Category",
        active: true,
        company_id: ObjectId("57a2218b31fdc2786406f980"),
        created_at: new Date()
    }, function(err, data){
        // data return ->
        //{
        // "_id" : null,
        // "name" : ""My Category",
        // "active" : true,
        // "created_at" : ISODate("2016-08-03T16:53:31.719Z"),
        // "company_id" : ObjectId("57a2218b31fdc2786406f980"),
        // "updated_at" : null,
        // "entity_status" : 1,
        // "reason" : null,
        // "__v" : 0
        //}
    });

victorldomingues avatar Aug 03 '16 17:08 victorldomingues