blob: 12035cc39a969a62991e6497f2c4d545df36e261 (
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
|
// Cannot implicitly shard accessed collections because of following errmsg: A single
// update/delete on a sharded collection must contain an exact match on _id or contain the shard
// key.
// @tags: [assumes_unsharded_collection]
/**
* Tests that using the $set update modifier to change only the type of a field will actually update
* the document, including any relevant indices.
*/
(function() {
"use strict";
var coll = db.set_type_change;
coll.drop();
assert.commandWorked(coll.ensureIndex({a: 1}));
assert.commandWorked(coll.insert({a: 2}));
var newVal = new NumberLong(2);
var res = coll.update({}, {$set: {a: newVal}});
assert.eq(res.nMatched, 1);
if (coll.getMongo().writeMode() == "commands")
assert.eq(res.nModified, 1);
// Make sure it actually changed the type.
var updated = coll.findOne();
assert(updated.a instanceof NumberLong, "$set did not update type of value: " + updated.a);
})();
|