diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2022-03-31 14:59:07 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-31 16:39:31 +0000 |
commit | 2d78530f2b590d205232bd3d65cb8f66500aa86f (patch) | |
tree | 6f896f05ea6c30a6a4f761ae21dd0e9965342fa0 /jstests | |
parent | e827fca1f586eb49ea1536b2985bd55a0105093b (diff) | |
download | mongo-2d78530f2b590d205232bd3d65cb8f66500aa86f.tar.gz |
SERVER-64872 Ensure `CollectionUUIDMismatch` from sharded `aggregate` does not incorrectly omit the actual collection
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/sharding/collection_uuid_aggregate.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/jstests/sharding/collection_uuid_aggregate.js b/jstests/sharding/collection_uuid_aggregate.js new file mode 100644 index 00000000000..11a864cc80c --- /dev/null +++ b/jstests/sharding/collection_uuid_aggregate.js @@ -0,0 +1,52 @@ +/** + * Tests the collectionUUID parameter of the aggregate command when not all shards own chunks for + * the collection. + * + * @tags: [ + * requires_fcv_60, + * ] + */ +(function() { +'use strict'; + +const st = new ShardingTest({shards: 2}); + +const db = st.s.getDB(jsTestName()); +assert.commandWorked(st.s.adminCommand({enableSharding: db.getName()})); +st.ensurePrimaryShard(db.getName(), st.shard0.shardName); + +const shardedColl = db.sharded; +const unshardedColl = db.unsharded; + +assert.commandWorked(shardedColl.insert({_id: 0})); +assert.commandWorked(unshardedColl.insert({_id: 2})); + +const uuid = function(coll) { + return assert.commandWorked(db.runCommand({listCollections: 1})) + .cursor.firstBatch.find(c => c.name === coll.getName()) + .info.uuid; +}; + +assert.commandWorked( + st.s.adminCommand({shardCollection: shardedColl.getFullName(), key: {_id: 1}})); + +// Move the chunk to shard1. +assert.commandWorked(st.s.adminCommand( + {moveChunk: shardedColl.getFullName(), find: {_id: 0}, to: st.shard1.shardName})); + +// Run an aggregate which will only target shard1, since shard0 does not own any chunks. +let res = assert.commandFailedWithCode(db.runCommand({ + aggregate: shardedColl.getName(), + pipeline: [{$indexStats: {}}], + cursor: {}, + collectionUUID: uuid(unshardedColl), +}), + ErrorCodes.CollectionUUIDMismatch); +jsTestLog('$indexStats result: ' + tojson(res)); +assert.eq(res.db, db.getName()); +assert.eq(res.collectionUUID, uuid(unshardedColl)); +assert.eq(res.expectedCollection, shardedColl.getName()); +assert.eq(res.actualCollection, unshardedColl.getName()); + +st.stop(); +})(); |