小编l00*_*00p的帖子

NodeJS + MongoDB: insertOne() - 从 result.ops 获取插入的文档

在我看到的文档中,我们可以使用返回的 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)

mongodb nosql node.js

2
推荐指数
1
解决办法
601
查看次数

标签 统计

mongodb ×1

node.js ×1

nosql ×1