summaryrefslogtreecommitdiff
path: root/jstests/sharding/SERVER-7379.js
blob: 8ad1a12fb801ad2e043e94bdcb2247c3e507b4bc (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var st = new ShardingTest({ shards: 2 });

st.adminCommand({ enablesharding: "test" });
st.adminCommand({ shardcollection: "test.offerChange", key: { "categoryId": 1, "store": 1, "_id": 1 } });

var db = st.s.getDB('test');
var offerChange = db.getCollection('offerChange');
var testDoc = { "_id": 123, "categoryId": 9881, "store": "NEW" }

offerChange.remove({}, false);
offerChange.insert(testDoc)
offerChange.update({ "_id": 123 }, { $set: { "store": "NEWEST" } }, true, false);
var gle = db.runCommand({ getLastError: 1 });
assert(gle.err != null, 'gleObj: ' + tojson(gle));
var doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

offerChange.remove({}, false);
offerChange.insert(testDoc)
offerChange.update({ "_id": 123 }, { "_id": 123, "categoryId": 9881, "store": "NEWEST" }, true, false);
var gle = db.runCommand({ getLastError: 1 });
assert(gle.err != null, 'gleObj: ' + tojson(gle));
var doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

offerChange.remove({}, false);
offerChange.insert(testDoc)
offerChange.save({ "_id": 123, "categoryId": 9881, "store": "NEWEST" })
var gle = db.runCommand({ getLastError: 1 });
assert(gle.err != null, 'gleObj: ' + tojson(gle));
var doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

offerChange.remove({}, false);
offerChange.insert(testDoc);
offerChange.update({ "_id": 123, "store": "NEW" }, { "_id": 123, "categoryId": 9881, "store": "NEWEST" }, true, false);
var gle = db.runCommand({ getLastError: 1 });
assert(gle.err != null, 'gleObj: ' + tojson(gle));
var doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

offerChange.remove({}, false);
offerChange.insert(testDoc);
offerChange.update({ "_id": 123, "categoryId": 9881 }, { "_id": 123, "categoryId": 9881, "store": "NEWEST" }, true, false);
var gle = db.runCommand({ getLastError: 1 });
assert(gle.err != null, 'gleObj: ' + tojson(gle));
var doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

st.stop();