2018-04-06 10:33:03 -04:00
|
|
|
// @tags: [requires_fastcount]
|
2010-03-02 10:10:00 -05:00
|
|
|
|
|
|
|
|
let t = db.arrayfind2;
|
|
|
|
|
t.drop();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
function go(prefix) {
|
|
|
|
|
assert.eq(3, t.count(), prefix + " A1");
|
|
|
|
|
assert.eq(3, t.find({a: {$elemMatch: {x: {$gt: 4}}}}).count(), prefix + " A2");
|
|
|
|
|
assert.eq(1, t.find({a: {$elemMatch: {x: {$lt: 2}}}}).count(), prefix + " A3");
|
|
|
|
|
assert.eq(
|
|
|
|
|
1,
|
|
|
|
|
t.find({a: {$all: [{$elemMatch: {x: {$lt: 4}}}, {$elemMatch: {x: {$gt: 5}}}]}}).count(),
|
|
|
|
|
prefix + " A4");
|
2013-10-10 18:27:49 -04:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.throws(function() {
|
|
|
|
|
return t.findOne({a: {$all: [1, {$elemMatch: {x: 3}}]}});
|
|
|
|
|
});
|
|
|
|
|
assert.throws(function() {
|
|
|
|
|
return t.findOne({a: {$all: [/a/, {$elemMatch: {x: 3}}]}});
|
|
|
|
|
});
|
2010-03-02 10:10:00 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [{x: 1}, {x: 5}]});
|
|
|
|
|
t.save({a: [{x: 3}, {x: 5}]});
|
|
|
|
|
t.save({a: [{x: 3}, {x: 6}]});
|
2010-03-02 10:10:00 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
go("no index");
|
2020-11-17 13:45:05 +00:00
|
|
|
t.createIndex({a: 1});
|
2016-03-09 12:17:50 -05:00
|
|
|
go("index(a)");
|