在我看到的文档中,我们可以使用返回的 insertOneWriteOpResultObject.ops 来检索插入的文档。(文档),但是这样做时我会回来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();
});
});
});
Run Code Online (Sandbox Code Playgroud)