2013-12-09 14:45:13 -05:00
|
|
|
// Basic examples for $bit
|
2014-02-19 12:45:53 -05:00
|
|
|
var res;
|
2013-12-09 14:45:13 -05:00
|
|
|
var coll = db.update_bit;
|
|
|
|
|
coll.drop();
|
|
|
|
|
|
|
|
|
|
// $bit and
|
2014-02-02 11:21:12 -05:00
|
|
|
coll.remove({})
|
2013-12-09 14:45:13 -05:00
|
|
|
coll.save({_id:1, a:NumberInt(2)});
|
2014-02-19 12:45:53 -05:00
|
|
|
res = coll.update({}, {$bit: {a: {and: NumberInt(4)}}})
|
|
|
|
|
assert.writeOK(res);
|
2013-12-09 14:45:13 -05:00
|
|
|
assert.eq(coll.findOne().a, 0)
|
|
|
|
|
|
|
|
|
|
// $bit or
|
2014-02-02 11:21:12 -05:00
|
|
|
coll.remove({})
|
2013-12-09 14:45:13 -05:00
|
|
|
coll.save({_id:1, a:NumberInt(2)});
|
2014-02-19 12:45:53 -05:00
|
|
|
res = coll.update({}, {$bit: {a: {or: NumberInt(4)}}})
|
|
|
|
|
assert.writeOK(res);
|
2013-12-09 14:45:13 -05:00
|
|
|
assert.eq(coll.findOne().a, 6)
|
|
|
|
|
|
|
|
|
|
// $bit xor
|
2014-02-02 11:21:12 -05:00
|
|
|
coll.remove({})
|
2013-12-09 14:45:13 -05:00
|
|
|
coll.save({_id:1, a:NumberInt(0)});
|
2014-02-19 12:45:53 -05:00
|
|
|
res = coll.update({}, {$bit: {a: {xor: NumberInt(4)}}})
|
|
|
|
|
assert.writeOK(res);
|
2013-12-09 14:45:13 -05:00
|
|
|
assert.eq(coll.findOne().a, 4)
|
2015-09-08 15:27:04 -04:00
|
|
|
|
|
|
|
|
// SERVER-19706 Empty bit operation.
|
|
|
|
|
res = coll.update({}, {$bit: {a: {}}});
|
|
|
|
|
assert.writeError(res);
|