1
如何在mongo-c-driver或mongo-cxx-driver中插入文档后得到_id
?如何在mongo-c-driver或mongo-cxx-driver中插入文档后获得`_id`?
以下代码片段来自mongo-shell,其中显示最后一行WriteResult
中的_id
字段。
db.coll.update(
{ item: "ZZZ135" },
{ item: "ZZZ135", stock: 5, tags: [ "database" ] },
{upsert: true}
)
WriteResult({
"nMatched" : 0,
"nUpserted" : 1,
"nModified" : 0,
"_id" : ObjectId("54455f33b247e073d7161b32")
})