(function() {
|
"use strict";
|
|
load("jstests/sharding/libs/create_sharded_collection_util.js");
|
|
const st = new ShardingTest({mongos: 1, config: 1, shards: 2, rs: {nodes: 1}});
|
|
const db = st.s.getDB("test");
|
const collection = db.getCollection("mycoll");
|
CreateShardedCollectionUtil.shardCollectionWithChunks(collection, {"x.y": 1}, [
|
{min: {"x.y": MinKey}, max: {"x.y": 0}, shard: st.shard0.shardName},
|
{min: {"x.y": 0}, max: {"x.y": 10}, shard: st.shard0.shardName},
|
{min: {"x.y": 10}, max: {"x.y": 20}, shard: st.shard1.shardName},
|
{min: {"x.y": 20}, max: {"x.y": MaxKey}, shard: st.shard1.shardName},
|
]);
|
|
assert.commandWorked(collection.insert({_id: 0, x: {y: 5}, counter: 0}));
|
|
const session = st.s.startSession({causalConsistency: false, retryWrites: false});
|
const sessionCollection = session.getDatabase(db.getName()).getCollection(collection.getName());
|
|
const updateCmd = {
|
updates: [{q: {"x.y": 5, _id: 0}, u: {$inc: {counter: 1}}}],
|
txnNumber: NumberLong(0),
|
};
|
|
const firstRes = assert.commandWorked(sessionCollection.runCommand("update", updateCmd));
|
assert.eq({n: firstRes.n, nModified: firstRes.nModified}, {n: 1, nModified: 1});
|
|
assert.commandWorked(db.adminCommand(
|
{moveChunk: collection.getFullName(), find: {"x.y": 5}, to: st.shard1.shardName}));
|
|
const secondRes = assert.commandWorked(sessionCollection.runCommand("update", updateCmd));
|
print(`secondRes: ${tojsononeline(secondRes)}`);
|
assert.eq(collection.findOne({_id: 0}), {_id: 0, x: {y: 5}, counter: 1});
|
|
st.stop();
|
})();
|