【发布时间】:2021-07-16 16:03:37
【问题描述】:
在我看到的文档中,我们可以使用返回的 insertOneWriteOpResultObject.ops 来检索插入的文档。 (Docs),但是这样做时我会返回undefined。
要重现的代码:
const collection = db.collection("testcollection");
collection.insertOne({"name": "Test_Name", "description": "Test desc."},
(err, result) => {
console.log("After Insert:\n");
console.log(result.ops); //undefined but should return the document
collection.find({}).toArray((err, docs) => {
console.log("Found:\n");
console.log(docs);
db.dropCollection("testcollection", (err, result) => {
client.close();
});
});
});
【问题讨论】: