summaryrefslogtreecommitdiff
path: root/jstests/update_replace.js
blob: 1bee0a8597a28824f11103fcc416b4167a40f4b3 (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
// This test checks validation of the replaced doc (on the server) for dots, $prefix and _id

t = db.jstests_update_replace;
t.drop();

// disable client side checks so we can test the server
DBCollection.prototype._validateForStorage = function() {};

// Should not allow "." in field names
t.save({_id:1, "a.a":1})
assert.gleError(db, "a.a");

// Should not allow "." in field names, embedded
t.save({_id:1, a :{"a.a":1}})
assert.gleError(db, "a: a.a");

// Should not allow "$"-prefixed field names, caught before "." check
t.save({_id:1, $a :{"a.a":1}})
assert.gleError(db, "$a: a.a");

// Should not allow "$"-prefixed field names
t.save({_id:1, $a: 1})
assert.gleError(db, "$a");

// _id validation checks

// Should not allow regex _id
t.save({_id: /a/})
assert.gleError(db, "_id regex");

// Should not allow regex _id, even if not first
t.save({a:2, _id: /a/})
assert.gleError(db, "a _id regex");

// Should not allow array _id
t.save({_id: [9]})
assert.gleError(db, "_id array");

// This is fine since _id isn't a top level field
t.save({a :{ _id: [9]}})
assert.gleSuccess(db, "embedded _id array");

// This is fine since _id isn't a top level field
t.save({b:1, a :{ _id: [9]}})
assert.gleSuccess(db, "b embedded _id array");