summaryrefslogtreecommitdiff
path: root/jstests/sharding/array_shard_key.js
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2014-02-05 17:43:15 -0500
committerRandolph Tan <randolph@10gen.com>2014-02-12 15:21:45 -0500
commit5e0365665f7244a9382b9bf078c890dce1cd5c03 (patch)
treebb6e4d5c62ba397726028ea197ad6f2a16656df9 /jstests/sharding/array_shard_key.js
parente203fc775578a42c88494639b15f9f67f350c4c1 (diff)
downloadmongo-5e0365665f7244a9382b9bf078c890dce1cd5c03.tar.gz
SERVER-9620 Index can be made multikey if a prefix of it is a shard key
Allowed sharded collections to have multikey indexes based on the invariant that shard key values can never be arrays.
Diffstat (limited to 'jstests/sharding/array_shard_key.js')
-rw-r--r--jstests/sharding/array_shard_key.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/jstests/sharding/array_shard_key.js b/jstests/sharding/array_shard_key.js
index 46ed72addd1..902c3227b8c 100644
--- a/jstests/sharding/array_shard_key.js
+++ b/jstests/sharding/array_shard_key.js
@@ -85,6 +85,29 @@ error = coll.getDB().getLastError()
assert.eq( error, null )
assert.eq( coll.find().itcount(), 0 )
+coll.ensureIndex({ _id : 1, i : 1, j: 1 });
+// Can insert document that will make index into a multi-key as long as it's not part of shard key.
+coll.remove();
+coll.insert({ i: 1, j: [1, 2] });
+error = coll.getDB().getLastError();
+assert.eq( error, null );
+assert.eq( coll.find().itcount(), 1 );
+
+// Same is true for updates.
+coll.remove();
+coll.insert({ _id: 1, i: 1 });
+coll.update({ _id: 1, i: 1 }, { _id: 1, i:1, j: [1, 2] });
+error = coll.getDB().getLastError();
+assert.eq( error, null );
+assert.eq( coll.find().itcount(), 1 );
+
+// Same for upserts.
+coll.remove();
+coll.update({ _id: 1, i: 1 }, { _id: 1, i:1, j: [1, 2] }, true);
+error = coll.getDB().getLastError();
+assert.eq( error, null );
+assert.eq( coll.find().itcount(), 1 );
+
printjson( "Sharding-then-inserting-multikey tested, now trying inserting-then-sharding-multikey" )
// Insert a bunch of data then shard over key which is an array