Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

mongodb js get id of inserted

collection.insert(objToInsert, function (err, result){
    if(err)console.log(err);
    else {
        console.log(result["ops"][0]["_id"]);
        // The above statement will output the id of the 
        // inserted object
       }
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mongodb #js #id #inserted
ADD COMMENT
Topic
Name
7+9 =