Answers for "how to get id of documents mongodb"

Go
11

mongo console find by id

db.collection.find({_id:ObjectId('5e208c18d598b806c869ca37')}).pretty()
Posted by: Guest on April-27-2020
-1

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
       }
});
Posted by: Guest on May-14-2020

Code answers related to "how to get id of documents mongodb"

Browse Popular Code Answers by Language