How to get _id
after upserting document in mongo-c-driver Or mongo-cxx-driver?
The following code snippet is from mongo-shell, Which shows the _id
field in last row of WriteResult
.
db.coll.update(
{ item: "ZZZ135" },
{ item: "ZZZ135", stock: 5, tags: [ "database" ] },
{upsert: true}
)
WriteResult({
"nMatched" : 0,
"nUpserted" : 1,
"nModified" : 0,
"_id" : ObjectId("54455f33b247e073d7161b32")
})