2017-03-23 14:07:50 -04:00
|
|
|
// Cannot implicitly shard accessed collections because of following errmsg: A single
|
|
|
|
|
// update/delete on a sharded collection must contain an exact match on _id or contain the shard
|
|
|
|
|
// key.
|
2017-11-28 10:10:44 -05:00
|
|
|
// @tags: [assumes_unsharded_collection, requires_non_retryable_writes]
|
2017-03-23 14:07:50 -04:00
|
|
|
|
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
|
2016-02-04 12:29:01 -05:00
|
|
|
coll.remove({});
|
2016-03-09 12:17:50 -05:00
|
|
|
coll.save({_id: 1, a: NumberInt(2)});
|
2016-02-04 12:29:01 -05:00
|
|
|
res = coll.update({}, {$bit: {a: {and: NumberInt(4)}}});
|
2014-02-19 12:45:53 -05:00
|
|
|
assert.writeOK(res);
|
2016-02-04 12:29:01 -05:00
|
|
|
assert.eq(coll.findOne().a, 0);
|
2013-12-09 14:45:13 -05:00
|
|
|
|
|
|
|
|
// $bit or
|
2016-02-04 12:29:01 -05:00
|
|
|
coll.remove({});
|
2016-03-09 12:17:50 -05:00
|
|
|
coll.save({_id: 1, a: NumberInt(2)});
|
2016-02-04 12:29:01 -05:00
|
|
|
res = coll.update({}, {$bit: {a: {or: NumberInt(4)}}});
|
2014-02-19 12:45:53 -05:00
|
|
|
assert.writeOK(res);
|
2016-02-04 12:29:01 -05:00
|
|
|
assert.eq(coll.findOne().a, 6);
|
2013-12-09 14:45:13 -05:00
|
|
|
|
|
|
|
|
// $bit xor
|
2016-02-04 12:29:01 -05:00
|
|
|
coll.remove({});
|
2016-03-09 12:17:50 -05:00
|
|
|
coll.save({_id: 1, a: NumberInt(0)});
|
2016-02-04 12:29:01 -05:00
|
|
|
res = coll.update({}, {$bit: {a: {xor: NumberInt(4)}}});
|
2014-02-19 12:45:53 -05:00
|
|
|
assert.writeOK(res);
|
2016-02-04 12:29:01 -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);
|