In the docs I see we can use the returned insertOneWriteOpResultObject.ops to retrieve the document inserted. (Docs), but when doing so I get back undefined
.
Code to reproduce:
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();
});
});
});
Check version of MongoDB Node.js Driver with command npm list mongodb
. If it is version 4 then you can not access result.ops
. In version 4 insertOne returns insertOneResult that have only 2 properties: acknowledged and insertedId.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With