|
The documentation for the output of update is incomplete about the value of update.n.
In particular, the value of update.n will also include any upserted documents in addition to documents, which were matched.
Here is the actual value from upserting into an empty collection:
MongoDB shell version: 3.2.0-rc2-97-g243188c
|
connecting to: test
|
> use Test;
|
switched to db Test
|
> var res = db.runCommand({ update: 'TestColl', updates: [ { q: { _id: 1 }, u: { _id: 1, value: 5 }, upsert: true } ] });
|
> res
|
{
|
"ok" : 1,
|
"nModified" : 0,
|
"n" : 1,
|
"upserted" : [
|
{
|
"index" : 0,
|
"_id" : 1
|
}
|
]
|
}
|
|