summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-05-23 09:53:26 -0400
committerDan Pasette <dan@mongodb.com>2014-06-01 10:44:03 -0400
commit6dc02ec1d08825bb5ecd9b76d786d0d86bf37885 (patch)
treed4a75a7975cb9f24bd7b25bf0681856f0e194cca /jstests
parent5900e7a03183f052bf5f2f17f177c65062ac75aa (diff)
downloadmongo-6dc02ec1d08825bb5ecd9b76d786d0d86bf37885.tar.gz
SERVER-13865 handle edge case for v2.4 when upserted _id not returned
(cherry picked from commit 090ea9a5ad1ed52e40b5a66df5ee1eab283845cb)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/multiVersion/batch_write_commands_update_sharded.js27
-rw-r--r--jstests/multiVersion/bulk_write_commands_update_singlenode.js25
2 files changed, 51 insertions, 1 deletions
diff --git a/jstests/multiVersion/batch_write_commands_update_sharded.js b/jstests/multiVersion/batch_write_commands_update_sharded.js
index 310da28d562..0138a0fba68 100644
--- a/jstests/multiVersion/batch_write_commands_update_sharded.js
+++ b/jstests/multiVersion/batch_write_commands_update_sharded.js
@@ -1,5 +1,5 @@
/**
- * This test checks update write command corner cases:
+ * This test checks update write command corner cases for mongos:
* -- nModified behavior
* -- other?
*/
@@ -82,6 +82,31 @@ var res = assert.commandWorked(coll24.getDB().runCommand(req));
assert.eq(undefined, res.nModified, tojson(res))
assert.eq(22, res.n, tojson(res))
+// Test non-OID upsert behavior
+
+// 2.6 mongod shard
+var upsertedId = ObjectId().toString();
+var req = {update:coll26.getName(),
+ updates:[
+ {q:{_id:upsertedId}, u:{$set:{a:1}}, upsert:true}
+ ]
+ };
+var res = assert.commandWorked(coll26.getDB().runCommand(req));
+assert.eq(0, res.nModified, "coll26: " + tojson(res));
+assert.eq(1, res.n, "coll26: " + tojson(res));
+assert.eq(upsertedId, res.upserted[0]._id, "coll26: " + tojson(res));
+
+// 2.4 mongod shard
+var upsertedId = ObjectId().toString();
+var req = {update:coll24.getName(),
+ updates:[
+ {q:{_id:upsertedId}, u:{$set:{a:1}}, upsert:true}
+ ]
+ };
+var res = assert.commandWorked(coll24.getDB().runCommand(req));
+assert.eq(1, res.n, "coll24: " + tojson(res));
+assert.eq(upsertedId, res.upserted[0]._id, "coll24: " + tojson(res));
+
// mixed version mongod shards
var req = {update:collMixed.getName(),
updates:[
diff --git a/jstests/multiVersion/bulk_write_commands_update_singlenode.js b/jstests/multiVersion/bulk_write_commands_update_singlenode.js
new file mode 100644
index 00000000000..f45cb108fe7
--- /dev/null
+++ b/jstests/multiVersion/bulk_write_commands_update_singlenode.js
@@ -0,0 +1,25 @@
+/**
+ * This test checks update bulk api corner cases for single nodes:
+ * -- upsert no _id
+ * -- other?
+ */
+
+var mongod24 = MongoRunner.runMongod({ binVersion : "2.4" });
+
+var coll24 = mongod24.getCollection("foo.bar");
+
+// 2.4 mongod fluent api
+
+var upsertedId = ObjectId().toString();
+var bulk = coll24.initializeOrderedBulkOp();
+bulk.find({ _id : upsertedId }).upsert().update({ $set : { a : 1 } });
+var res = bulk.execute();
+printjson(res);
+assert.eq(1, res.nUpserted);
+assert.eq(upsertedId, res.getUpsertedIdAt(0)._id);
+
+jsTest.log("DONE!");
+
+MongoRunner.stopMongod(mongod24);
+
+