summaryrefslogtreecommitdiff
path: root/jstests/sharding/SERVER-7379.js
blob: a98161f101e4f0256ea446907254a02e9fafdb80 (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
var st = new ShardingTest({shards: 2});

st.adminCommand({enablesharding: "test"});
st.ensurePrimaryShard('test', 'shard0001');
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);
assert.writeError(offerChange.update({_id: 123}, {$set: {store: "NEWEST"}}, true, false));
var doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

offerChange.remove({}, false);
offerChange.insert(testDoc);
assert.writeError(
    offerChange.update({_id: 123}, {_id: 123, categoryId: 9881, store: "NEWEST"}, true, false));
doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

offerChange.remove({}, false);
offerChange.insert(testDoc);
assert.writeError(offerChange.save({"_id": 123, "categoryId": 9881, "store": "NEWEST"}));
doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

offerChange.remove({}, false);
offerChange.insert(testDoc);
assert.writeError(offerChange.update(
    {_id: 123, store: "NEW"}, {_id: 123, categoryId: 9881, store: "NEWEST"}, true, false));
doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

offerChange.remove({}, false);
offerChange.insert(testDoc);
assert.writeError(offerChange.update(
    {_id: 123, categoryId: 9881}, {_id: 123, categoryId: 9881, store: "NEWEST"}, true, false));
doc = offerChange.findOne();
assert(friendlyEqual(doc, testDoc), 'doc changed: ' + tojson(doc));

st.stop();