summaryrefslogtreecommitdiff
path: root/jstests/core/where4.js
blob: 612dba59e674f5ded48a92b5d815f7159311fd0d (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
var myDB = db.getSiblingDB("where4");

myDB.dropDatabase();

assert.writeOK(myDB.where4.insert({x: 1, y: 1}));
assert.writeOK(myDB.where4.insert({x: 2, y: 1}));

assert.writeOK(myDB.where4.update(
    {
      $where: function() {
          return this.x == 1;
      }
    },
    {$inc: {y: 1}},
    false,
    true));

assert.eq(2, myDB.where4.findOne({x: 1}).y);
assert.eq(1, myDB.where4.findOne({x: 2}).y);

// Test that where queries work with stored javascript
assert.writeOK(myDB.system.js.save({
    _id: "where4_addOne",
    value: function(x) {
        return x + 1;
    }
}));

assert.writeOK(
    myDB.where4.update({$where: "where4_addOne(this.x) == 2"}, {$inc: {y: 1}}, false, true));

assert.eq(3, myDB.where4.findOne({x: 1}).y);
assert.eq(1, myDB.where4.findOne({x: 2}).y);