summaryrefslogtreecommitdiff
path: root/jstests/core/set_type_change.js
blob: ede59f7bcdef7a96776690c7cad06c54ab9b1481 (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
// 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.
 */

load("jstests/libs/analyze_plan.js");  // For 'isIndexOnly'.

(function() {
    "use strict";

    var coll = db.set_type_change;
    coll.drop();
    assert.commandWorked(coll.ensureIndex({a: 1}));

    assert.writeOK(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);
})();