summaryrefslogtreecommitdiff
path: root/jstests/multiVersion
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-05-23 09:53:26 -0400
committerGreg Studer <greg@10gen.com>2014-05-23 09:53:26 -0400
commit090ea9a5ad1ed52e40b5a66df5ee1eab283845cb (patch)
tree0efd30dda90abd3e044d27e31b60015575bfd63e /jstests/multiVersion
parent54845ac08d80b9556cbcbea711ad0529feb09c0f (diff)
downloadmongo-090ea9a5ad1ed52e40b5a66df5ee1eab283845cb.tar.gz
SERVER-13865 handle edge case for v2.4 when upserted _id not returned
Diffstat (limited to 'jstests/multiVersion')
-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);
+
+