Reputation: 727
I want to get an '_id' of newly inserted document in MongoDB. Finding this solution Get the _id of inserted document in Mongo database in NodeJS I tried this simple code in mongo shell:
var order = { number: 2, completed: false };
db.orders.insert(order, function(err,docsInserted){
console.log(docsInserted);
});
But I get the next:
WriteResult({ "nInserted" : 1 })
What is wrong here?
Upvotes: 0
Views: 894
Reputation: 2253
The answer/method that you are trying to utilise is referring to the API for MongoDB driver for node.js. The equivalent expression in the mongo shell will only return the write result (the callback won't work in the shell).
To review the inserted document in the shell, you still need to make use of find
as suggested here in the docs.
Upvotes: 1