summaryrefslogtreecommitdiff
path: root/jstests/updateh.js
blob: 2a39f6a097525a96bf6c7671c5e9b2e62a56c187 (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
// Disallow $ in field names - SERVER-3730

t = db.jstest_updateh
t.drop()

t.insert( {x:1} )

t.update( {x:1}, {$set: {y:1}} ) // ok
e = db.getLastErrorObj()
assert.eq( e.err, null )

t.update( {x:1}, {$set: {$z:1}} ) // not ok
e = db.getLastErrorObj()
assert( e.err != null )

// TODO: This shouldn't be supported, and it isn't with the new update framework, but we
// currently don't have a good way to check which mode we are in. When we do have that, add
// this test guarded under that condition. Or, when we remove the old update path just enable
// this test.
//
// t.update( {x:1}, {$set: {'a.$b':1}} ) // not ok
// e = db.getLastErrorObj()
// assert( e.err != null )

t.update( {x:1}, {$unset: {$z:1}} ) // unset ok to remove bad fields
e = db.getLastErrorObj()
assert.eq( e.err, null )

t.update( {x:1}, {$inc: {$z:1}} ) // not ok
e = db.getLastErrorObj()
assert( e.err != null )

t.update( {x:1}, {$pushAll: {$z:[1,2,3]}} ) // not ok
e = db.getLastErrorObj()
assert( e.err != null )

t.update( {x:1}, {$pushAll: {z:[1,2,3]}} ) // ok
e = db.getLastErrorObj()
assert.eq( e.err, null )