File: apply_ops1.js

package info (click to toggle)
mongodb 1%3A2.0.6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,204 kB
  • sloc: cpp: 109,783; ansic: 101,073; python: 2,287; perl: 395; makefile: 370; sh: 242; asm: 46
file content (51 lines) | stat: -rw-r--r-- 1,753 bytes parent folder | download
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

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

assert.eq( 0 , t.find().count() , "A0" );
db.runCommand( { applyOps : [ { "op" : "i" , "ns" : t.getFullName() , "o" : { _id : 5 , x : 17 } } ] } )
assert.eq( 1 , t.find().count() , "A1" );

o = { _id : 5 , x : 17 }
assert.eq( o , t.findOne() , "A2" );

res = db.runCommand( { applyOps : [ 
    { "op" : "u" , "ns" : t.getFullName() , "o2" : { _id : 5 } , "o" : { $inc : { x : 1 } } } ,
    { "op" : "u" , "ns" : t.getFullName() , "o2" : { _id : 5 } , "o" : { $inc : { x : 1 } } } 
] } )

o.x++;
o.x++;

assert.eq( 1 , t.find().count() , "A3" );
assert.eq( o , t.findOne() , "A4" );


res = db.runCommand( { applyOps : 
                       [ 
                           { "op" : "u" , "ns" : t.getFullName() , "o2" : { _id : 5 } , "o" : { $inc : { x : 1 } } } ,
                           { "op" : "u" , "ns" : t.getFullName() , "o2" : { _id : 5 } , "o" : { $inc : { x : 1 } } } 
                       ]
                       , 
                       preCondition : [ { ns : t.getFullName() , q : { _id : 5 } , res : { x : 19 } } ]
                     }  );

o.x++;
o.x++;

assert.eq( 1 , t.find().count() , "B1" );
assert.eq( o , t.findOne() , "B2" );


res = db.runCommand( { applyOps : 
                       [ 
                           { "op" : "u" , "ns" : t.getFullName() , "o2" : { _id : 5 } , "o" : { $inc : { x : 1 } } } ,
                           { "op" : "u" , "ns" : t.getFullName() , "o2" : { _id : 5 } , "o" : { $inc : { x : 1 } } } 
                       ]
                       , 
                       preCondition : [ { ns : t.getFullName() , q : { _id : 5 } , res : { x : 19 } } ]
                     }  );

assert.eq( 1 , t.find().count() , "B3" );
assert.eq( o , t.findOne() , "B4" );