mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
48 lines
1.9 KiB
JavaScript
48 lines
1.9 KiB
JavaScript
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();
|