|
The behavior can clearly be seen in this test: apply_ops_upsert.js .
Ops:
pDB.createCollection(collName);
|
|
let count = 0;
|
assert.commandWorked(pDB[collName].update({_id: count}, {x: count++}, {upsert: true}));
|
assert.commandWorked(pDB.runCommand(
|
{applyOps: [{op: "u", ns: nss(dbName, collName), o2: {_id: count}, o: {$set: {x: count++}}}]}));
|
assert.commandWorked(pDB.runCommand({
|
applyOps: [{op: "u", ns: nss(dbName, collName), o2: {_id: count}, o: {$set: {x: count++}}}],
|
allowAtomic: false
|
}));
|
assert.commandWorked(pDB.runCommand({
|
applyOps: [
|
{op: "u", ns: nss(dbName, collName), o2: {_id: count}, o: {$set: {x: count}}},
|
{op: "c", ns: nss(dbName, "$cmd"), o: {create: "other" + count++}}
|
]
|
}));
|
assert.commandWorked(pDB[collName].insert({_id: count++}));
|
assert.commandWorked(
|
pDB.runCommand({applyOps: [{op: "i", ns: nss(dbName, collName), o: {_id: count++}}]}));
|
assert.commandWorked(pDB.runCommand(
|
{applyOps: [{op: "i", ns: nss(dbName, collName), o: {_id: count++}}], allowAtomic: false}));
|
assert.commandWorked(pDB.runCommand({
|
applyOps: [
|
{op: "i", ns: nss(dbName, collName), o: {_id: count}},
|
{op: "c", ns: nss(dbName, "$cmd"), o: {create: "other" + count++}}
|
]
|
}));
|
|
assert.commandWorked(pDB["end"].insert({_id: 0}));
|
You can see the oplog entries here:
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.758-0500 [jsTest] ----
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.758-0500 [jsTest] Dumping the latest 100 documents that match { } from the oplog oplog.rs of jedbartlet:20020
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.758-0500 [jsTest] { "op" : "i", "ns" : "foo.end", "ui" : UUID("e981704b-bf89-447e-87d8-3a75d2afe760"), "o" : { "_id" : 0 }, "ts" : Timestamp(1575498632, 7), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:32.332Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.758-0500 [jsTest] { "op" : "c", "ns" : "foo.$cmd", "ui" : UUID("e981704b-bf89-447e-87d8-3a75d2afe760"), "o" : { "create" : "end", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" } }, "ts" : Timestamp(1575498632, 6), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:32.331Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.758-0500 [jsTest] { "op" : "c", "ns" : "foo.$cmd", "ui" : UUID("1cdd1846-12c4-4660-a778-74544a5afe0a"), "o" : { "create" : "other7" }, "ts" : Timestamp(1575498632, 5), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:32.173Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.758-0500 [jsTest] { "op" : "i", "ns" : "foo.coll", "ui" : UUID("875e448b-688d-448e-abe2-d426633ce1ba"), "o" : { "_id" : 7 }, "ts" : Timestamp(1575498632, 4), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:32.096Z"), "v" : NumberLong(2), "fromMigrate" : true }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.758-0500 [jsTest] { "op" : "i", "ns" : "foo.coll", "ui" : UUID("875e448b-688d-448e-abe2-d426633ce1ba"), "o" : { "_id" : 6 }, "ts" : Timestamp(1575498632, 3), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:32.076Z"), "v" : NumberLong(2), "fromMigrate" : true }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "c", "ns" : "foo.$cmd", "o" : { "applyOps" : [ { "op" : "i", "ns" : "foo.coll", "o" : { "_id" : 5 }, "ui" : UUID("875e448b-688d-448e-abe2-d426633ce1ba") } ], "lsid" : { "id" : UUID("880314e7-a1d4-4204-b875-72e2d260935c") }, "$clusterTime" : { "clusterTime" : Timestamp(1575498632, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } }, "$readPreference" : { "mode" : "secondaryPreferred" }, "$db" : "foo" }, "ts" : Timestamp(1575498632, 2), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:32.056Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "i", "ns" : "foo.coll", "ui" : UUID("875e448b-688d-448e-abe2-d426633ce1ba"), "o" : { "_id" : 4 }, "ts" : Timestamp(1575498632, 1), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:32.032Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "c", "ns" : "foo.$cmd", "ui" : UUID("a3e299a0-6cd0-422a-b680-9ef522625e2a"), "o" : { "create" : "other3" }, "ts" : Timestamp(1575498631, 6), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:32.004Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "i", "ns" : "foo.coll", "ui" : UUID("875e448b-688d-448e-abe2-d426633ce1ba"), "o" : { "_id" : 3, "x" : 3 }, "ts" : Timestamp(1575498631, 5), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:31.925Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "i", "ns" : "foo.coll", "ui" : UUID("875e448b-688d-448e-abe2-d426633ce1ba"), "o" : { "_id" : 2, "x" : 2 }, "ts" : Timestamp(1575498631, 4), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:31.904Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "c", "ns" : "foo.$cmd", "o" : { "applyOps" : [ { "op" : "u", "ns" : "foo.coll", "o2" : { "_id" : 1 }, "o" : { "$set" : { "x" : 1 } }, "ui" : UUID("875e448b-688d-448e-abe2-d426633ce1ba") } ], "lsid" : { "id" : UUID("880314e7-a1d4-4204-b875-72e2d260935c") }, "$clusterTime" : { "clusterTime" : Timestamp(1575498631, 2), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } }, "$readPreference" : { "mode" : "secondaryPreferred" }, "$db" : "foo" }, "ts" : Timestamp(1575498631, 3), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:31.882Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "i", "ns" : "foo.coll", "ui" : UUID("875e448b-688d-448e-abe2-d426633ce1ba"), "o" : { "_id" : 0, "x" : 0 }, "ts" : Timestamp(1575498631, 2), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:31.845Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "c", "ns" : "foo.$cmd", "ui" : UUID("875e448b-688d-448e-abe2-d426633ce1ba"), "o" : { "create" : "coll", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" } }, "ts" : Timestamp(1575498631, 1), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:31.802Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "n", "ns" : "", "o" : { "awaitLastStableRecoveryTimestamp" : 1 }, "ts" : Timestamp(1575498628, 1), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:28.791Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.759-0500 [jsTest] { "op" : "n", "ns" : "", "o" : { "msg" : "Reconfig set", "version" : 2 }, "ts" : Timestamp(1575498627, 5), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:27.092Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.760-0500 [jsTest] { "op" : "i", "ns" : "admin.system.keys", "ui" : UUID("99e2e03a-accc-49c0-9114-fd624554896b"), "o" : { "_id" : NumberLong("6766715077857902594"), "purpose" : "HMAC", "key" : BinData(0,"JKUgiC/83p8rvi5y6g1Mo7Rcb5Q="), "expiresAt" : Timestamp(1591050627, 0) }, "ts" : Timestamp(1575498627, 4), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:27.084Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.760-0500 [jsTest] { "op" : "i", "ns" : "admin.system.keys", "ui" : UUID("99e2e03a-accc-49c0-9114-fd624554896b"), "o" : { "_id" : NumberLong("6766715077857902593"), "purpose" : "HMAC", "key" : BinData(0,"4YC20NAVAGOGyhvLrUuJMMZYYbI="), "expiresAt" : Timestamp(1583274627, 0) }, "ts" : Timestamp(1575498627, 3), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:27.068Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.760-0500 [jsTest] { "op" : "c", "ns" : "admin.$cmd", "ui" : UUID("99e2e03a-accc-49c0-9114-fd624554896b"), "o" : { "create" : "system.keys", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" } }, "ts" : Timestamp(1575498627, 2), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:27.066Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.760-0500 [jsTest] { "op" : "n", "ns" : "", "o" : { "msg" : "new primary" }, "ts" : Timestamp(1575498627, 1), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:27Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.760-0500 [jsTest] { "op" : "c", "ns" : "config.$cmd", "ui" : UUID("25623e24-8b6d-4720-8e4f-821fa124f459"), "o" : { "create" : "transactions", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" } }, "ts" : Timestamp(1575498626, 3), "t" : NumberLong(1), "wall" : ISODate("2019-12-04T22:30:26.998Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.760-0500 [jsTest] { "op" : "n", "ns" : "", "o" : { "msg" : "initiating set" }, "ts" : Timestamp(1575498626, 1), "wall" : ISODate("2019-12-04T22:30:26.750Z"), "v" : NumberLong(2) }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:32.760-0500 [jsTest] ----
|
And the change stream events here:
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.047-0500 {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.047-0500 "_id" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.047-0500 "_data" : "825DE83387000000022B022C0100296E5A1004875E448B688D448EABE2D426633CE1BA461E5F696400290004",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.047-0500 "_typeBits" : BinData(0,"QA==")
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.047-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.047-0500 "operationType" : "insert",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 "clusterTime" : Timestamp(1575498631, 2),
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 "fullDocument" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 "_id" : 0,
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 "x" : 0
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 "ns" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 "db" : "foo",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 "coll" : "coll"
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 "documentKey" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 "_id" : 0
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.048-0500 }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.094-0500 {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.094-0500 "_id" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.094-0500 "_data" : "825DE83387000000042B022C0100296E5A1004875E448B688D448EABE2D426633CE1BA461E5F6964002B040004",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.094-0500 "_typeBits" : BinData(0,"QA==")
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.094-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.094-0500 "operationType" : "insert",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.094-0500 "clusterTime" : Timestamp(1575498631, 4),
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.094-0500 "fullDocument" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 "_id" : 2,
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 "x" : 2
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 "ns" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 "db" : "foo",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 "coll" : "coll"
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 "documentKey" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 "_id" : 2
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.095-0500 }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.128-0500 {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.128-0500 "_id" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.128-0500 "_data" : "825DE83387000000052B022C0100296E5A1004875E448B688D448EABE2D426633CE1BA461E5F6964002B060004",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.128-0500 "_typeBits" : BinData(0,"QA==")
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.128-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.128-0500 "operationType" : "insert",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.128-0500 "clusterTime" : Timestamp(1575498631, 5),
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.129-0500 "fullDocument" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.129-0500 "_id" : 3,
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.129-0500 "x" : 3
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.129-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.129-0500 "ns" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.129-0500 "db" : "foo",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.129-0500 "coll" : "coll"
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.129-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.129-0500 "documentKey" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.130-0500 "_id" : 3
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.130-0500 }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.130-0500 }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.161-0500 {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.161-0500 "_id" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.161-0500 "_data" : "825DE83388000000012B022C0100296E5A1004875E448B688D448EABE2D426633CE1BA461E5F6964002B080004",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.161-0500 "_typeBits" : BinData(0,"QA==")
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.161-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.162-0500 "operationType" : "insert",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.162-0500 "clusterTime" : Timestamp(1575498632, 1),
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.162-0500 "fullDocument" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.162-0500 "_id" : 4
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.162-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.162-0500 "ns" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.162-0500 "db" : "foo",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.162-0500 "coll" : "coll"
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.163-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.163-0500 "documentKey" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.163-0500 "_id" : 4
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.163-0500 }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.163-0500 }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.195-0500 {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.195-0500 "_id" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.195-0500 "_data" : "825DE83388000000072B022C0100296E5A1004E981704BBF89447E87D83A75D2AFE760461E5F696400290004",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.195-0500 "_typeBits" : BinData(0,"QA==")
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.195-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.195-0500 "operationType" : "insert",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.196-0500 "clusterTime" : Timestamp(1575498632, 7),
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.196-0500 "fullDocument" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.196-0500 "_id" : 0
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.196-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.196-0500 "ns" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.196-0500 "db" : "foo",
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.197-0500 "coll" : "end"
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.197-0500 },
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.197-0500 "documentKey" : {
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.197-0500 "_id" : 0
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.197-0500 }
|
[js_test:apply_ops_upsert] 2019-12-04T17:30:33.197-0500 }
|
|