summaryrefslogtreecommitdiff
path: root/jstests/updatee.js
blob: 228eba018d6afc43e0bdb235b666b0df024627a3 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// big numeric updates (used to overflow)

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

var o = { "_id" : 1, 
          "actual" : { 
        "key1" : "val1", 
        "key2" : "val2", 
        "001" : "val3", 
        "002" : "val4", 
        "0020000000000000000000" : "val5" 
    }, 
          "profile-id" : "test" };


t.insert( o );
assert.eq( o , t.findOne() , "A1" );

t.update({"profile-id" : "test"}, {$set: {"actual.0030000000000000000000": "val6"}});

var q = t.findOne();

// server-1347
assert.eq(q.actual["0020000000000000000000"], "val5", "A2");
assert.eq(q.actual["0030000000000000000000"], "val6", "A3");

t.update({"profile-id" : "test"}, {$set: {"actual.02": "v4"}});

q = t.findOne();
assert.eq(q.actual["02"], "v4", "A4");
assert(!q.actual["002"], "A5");

t.update({"_id" : 1}, {$set : {"actual.2139043290148390248219423941.b" : 4}});
q = t.findOne();
assert.eq(q.actual["2139043290148390248219423941"].b, 4, "A6");

// non-nested
t.update({"_id" : 1}, {$set : {"7213647182934612837492342341" : 1}});
t.update({"_id" : 1}, {$set : {"7213647182934612837492342342" : 2}});

q = t.findOne();
assert.eq(q["7213647182934612837492342341"], 1, "A7 1");
assert.eq(q["7213647182934612837492342342"], 2, "A7 2");

// 0s
t.update({"_id" : 1}, {$set : {"actual.000" : "val000"}});
q = t.findOne();
assert.eq(q.actual["000"], "val000", "A8 zeros");

t.update({"_id" : 1}, {$set : {"actual.00" : "val00"}});
q = t.findOne();
assert.eq(q.actual["00"], "val00", "A8 00");
assert(!q.actual["000"], "A9");

t.update({"_id" : 1}, {$set : {"actual.000" : "val000"}});
q = t.findOne();
assert.eq(q.actual["000"], "val000", "A9");
assert(!q.actual["00"], "A10");

t.update({"_id" : 1}, {$set : {"actual.01" : "val01"}});
q = t.findOne();
assert.eq(q.actual["000"], "val000", "A11");
assert.eq(q.actual["01"], "val01", "A12");

// shouldn't work, but shouldn't do anything too heinous, either
t.update({"_id" : 1}, {$set : {"0.." : "val01"}});
t.update({"_id" : 1}, {$set : {"0..0" : "val01"}});
t.update({"_id" : 1}, {$set : {".0" : "val01"}});
t.update({"_id" : 1}, {$set : {"..0" : "val01"}});
t.update({"_id" : 1}, {$set : {"0.0..0" : "val01"}});