summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/update_post_image_validation.js
blob: 228d449f82803c4fc5f855b94f2ab385d8f6aea2 (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
// Verify that the update system correctly rejects invalid entries during post-image validation.
// @tags: [
// ]
(function() {
"use strict";

const conn = MongoRunner.runMongod();
assert.neq(null, conn, "mongod was unable to start up");

const testDB = conn.getDB("test");

// Test validation of elements added to an array that is represented in a "deserialized" format
// in mutablebson. The added element is valid.
assert.commandWorked(testDB.coll.insert({_id: 0, a: []}));
assert.commandWorked(
    testDB.coll.update({_id: 0}, {$set: {"a.1": 0, "a.0": {$ref: "coll", $db: "test"}}}));
assert.docEq({_id: 0, a: [{$ref: "coll", $db: "test"}, 0]}, testDB.coll.findOne({_id: 0}));

// Test validation of modified array elements that are accessed using a string that is
// numerically equivalent to their fieldname. The modified element is valid.
assert.commandWorked(testDB.coll.insert({_id: 1, a: [0]}));
assert.commandWorked(testDB.coll.update({_id: 1}, {$set: {"a.00": {$ref: "coll", $db: "test"}}}));
assert.docEq({_id: 1, a: [{$ref: "coll", $db: "test"}]}, testDB.coll.findOne({_id: 1}));

MongoRunner.stopMongod(conn);
}());