如何print/use保存()数据结果mongoshell
How to print/use save() data result mongo shell
我正在从 mongo shell 的集合中添加一条记录,并且添加成功,
var demoData = db.getCollection('demoCollection').save({
"name": "My Name",
"about": "About my self",
"createdAt": new Date(Date.now()).toISOString()
});
我想在另一个操作中使用上面添加的记录_id
,
但我无法打印 demoData
或 demoData._id
、
的结果
我尝试了以下选项,
print(demoData._id); // returns '[unknown type]'
printJson(demoData); // Not printing
printJson(demoData.toArray()); // Not printing
save
returns一个WriteResult。尝试:
MongoDB Enterprise ruby-driver-rs:PRIMARY> x={a:1}
{ "a" : 1 }
MongoDB Enterprise ruby-driver-rs:PRIMARY> db.foo.save(x)
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise ruby-driver-rs:PRIMARY> x
{ "a" : 1, "_id" : ObjectId("5f04601ac17c40d26f231e47") }
我正在从 mongo shell 的集合中添加一条记录,并且添加成功,
var demoData = db.getCollection('demoCollection').save({
"name": "My Name",
"about": "About my self",
"createdAt": new Date(Date.now()).toISOString()
});
我想在另一个操作中使用上面添加的记录_id
,
但我无法打印 demoData
或 demoData._id
、
我尝试了以下选项,
print(demoData._id); // returns '[unknown type]'
printJson(demoData); // Not printing
printJson(demoData.toArray()); // Not printing
save
returns一个WriteResult。尝试:
MongoDB Enterprise ruby-driver-rs:PRIMARY> x={a:1}
{ "a" : 1 }
MongoDB Enterprise ruby-driver-rs:PRIMARY> db.foo.save(x)
WriteResult({ "nInserted" : 1 })
MongoDB Enterprise ruby-driver-rs:PRIMARY> x
{ "a" : 1, "_id" : ObjectId("5f04601ac17c40d26f231e47") }