node.js - 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();
});
});
});
解决方案
推荐阅读
- python - 当玩家回答时如何再次运行我的代码?
- python - Python - 迭代复杂列表比嵌套 for 循环更好的方法
- python - Python subclassing - how to update class attribute that is used by another class attribute
- apache-kafka - Kafka Idempotent producer
- php - 试图从数据库中获取数据并显示到 Dropbox
- dask - 恢复预计算索引
- python - How to make a new dataframe to store the average values of the original dataframe's columns' bins?
- nlp - Spacy动词亮点?
- java - 如何将现有 WebEment 添加到另一个 WebEment Selenium Java
- clickhouse - 在 Clickhouse 集群中获取重复项