2020-08-13 19:13:40 -04:00
|
|
|
// @tags: [
|
|
|
|
|
// requires_fastcount,
|
2024-12-27 16:01:08 +04:00
|
|
|
// requires_getmore
|
2020-08-13 19:13:40 -04:00
|
|
|
// ]
|
2009-12-31 14:30:04 -05:00
|
|
|
|
|
|
|
|
let t = db.arrayfind1;
|
|
|
|
|
t.drop();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [{x: 1}]});
|
|
|
|
|
t.save({a: [{x: 1, y: 2, z: 1}]});
|
|
|
|
|
t.save({a: [{x: 1, y: 1, z: 3}]});
|
2009-12-31 14:30:04 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
function test(exptected, q, name) {
|
|
|
|
|
assert.eq(exptected, t.find(q).itcount(), name + " " + tojson(q) + " itcount");
|
|
|
|
|
assert.eq(exptected, t.find(q).count(), name + " " + tojson(q) + " count");
|
2009-12-31 14:30:04 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
test(3, {}, "A1");
|
|
|
|
|
test(1, {"a.y": 2}, "A2");
|
|
|
|
|
test(1, {"a": {x: 1}}, "A3");
|
2025-08-21 10:17:44 -07:00
|
|
|
test(3, {"a": {$elemMatch: {x: 1}}}, "A4"); // SERVER-377
|
2009-12-31 14:30:04 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.save({a: [{x: 2}]});
|
|
|
|
|
t.save({a: [{x: 3}]});
|
|
|
|
|
t.save({a: [{x: 4}]});
|
2009-12-31 14:30:04 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(1, t.find({a: {$elemMatch: {x: 2}}}).count(), "B1");
|
|
|
|
|
assert.eq(2, t.find({a: {$elemMatch: {x: {$gt: 2}}}}).count(), "B2");
|
2009-12-31 15:18:43 -05:00
|
|
|
|
2020-11-17 13:45:05 +00:00
|
|
|
t.createIndex({"a.x": 1});
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(1, t.find({a: {$elemMatch: {x: 2}}}).count(), "D1");
|
|
|
|
|
assert.eq(3, t.find({"a.x": 1}).count(), "D2.1");
|
|
|
|
|
assert.eq(3, t.find({"a.x": {$gt: 1}}).count(), "D2.2");
|
|
|
|
|
assert.eq(2, t.find({a: {$elemMatch: {x: {$gt: 2}}}}).count(), "D3");
|
2009-12-31 15:18:43 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(2, t.find({a: {$ne: 2, $elemMatch: {x: {$gt: 2}}}}).count(), "E1");
|