summaryrefslogtreecommitdiff
path: root/jstests/sharding/unsharded_collection_targetting.js
blob: 4ae771e3d6e7c778f386fcf61c3e6d4ae1193306 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Tests that a stale mongos would route writes correctly to the right shard after
// an unsharded collection was moved to another shard.
(function() {
"use strict";

const st = new ShardingTest({
    shards: 2,
    mongos: 2,
    rs: {
        nodes: 1,
    },
});

const testName = 'test';
const mongosDB = st.s0.getDB(testName);

// Ensure that shard1 is the primary shard.
assert.commandWorked(mongosDB.adminCommand({enableSharding: mongosDB.getName()}));
st.ensurePrimaryShard(mongosDB.getName(), st.rs1.getURL());

// Before moving the collection, issue a write through mongos2 to make it aware
// about the location of the collection before the move.
const mongos2DB = st.s1.getDB(testName);
const mongos2Coll = mongos2DB[testName];
assert.commandWorked(mongos2Coll.insert({_id: 0, a: 0}));

st.ensurePrimaryShard(mongosDB.getName(), st.rs0.getURL());

assert.commandWorked(mongos2Coll.insert({_id: 1, a: 0}));

st.stop();
})();