2017-11-28 10:10:44 -05:00
|
|
|
// @tags: [requires_non_retryable_writes]
|
2011-04-04 23:29:54 -07:00
|
|
|
|
|
|
|
|
let t = db.jstests_array_match2;
|
|
|
|
|
t.drop();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [{1: 4}, 5]});
|
2011-04-04 23:29:54 -07:00
|
|
|
// When the array index is the last field, both of these match types work.
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(1, t.count({'a.1': 4}));
|
|
|
|
|
assert.eq(1, t.count({'a.1': 5}));
|
2011-04-04 23:29:54 -07:00
|
|
|
|
2014-02-02 11:21:12 -05:00
|
|
|
t.remove({});
|
2011-04-04 23:29:54 -07:00
|
|
|
// When the array index is not the last field, only one of the match types works.
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [{1: {foo: 4}}, {foo: 5}]});
|
|
|
|
|
assert.eq(1, t.count({'a.1.foo': 4}));
|
|
|
|
|
assert.eq(1, t.count({'a.1.foo': 5}));
|
2011-04-05 10:45:25 -07:00
|
|
|
|
|
|
|
|
// Same issue with the $exists operator
|
2014-02-02 11:21:12 -05:00
|
|
|
t.remove({});
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [{1: {foo: 4}}, {}]});
|
|
|
|
|
assert.eq(1, t.count({'a.1': {$exists: true}}));
|
|
|
|
|
assert.eq(1, t.count({'a.1.foo': {$exists: true}}));
|