我想在MongoDB中获取新插入文档的'_id'。找到这个解决方案Get the _id of inserted document in Mongo database in NodeJS我在mongo shell中尝试了这个简单的代码:
reshape2
但我得到了下一个:
var order = { number: 2, completed: false };
db.orders.insert(order, function(err,docsInserted){
console.log(docsInserted);
});
这里有什么问题?
答案 0 :(得分:1)
您尝试使用的答案/方法是指MongoDB driver for node.js的API。 mongo shell中的等效表达式只返回写入结果(回调函数不能在shell中运行)。
要在shell中查看插入的文档,您仍需要按照文档中的建议here使用find
。