2020-08-13 19:13:40 -04:00
|
|
|
/**
|
2021-03-01 13:19:14 -05:00
|
|
|
* Basic test for querying on documents containing arrays.
|
2024-12-27 16:01:08 +04:00
|
|
|
* @tags: [
|
|
|
|
|
* requires_getmore
|
|
|
|
|
* ]
|
2020-08-13 19:13:40 -04:00
|
|
|
*/
|
2025-08-21 10:17:44 -07:00
|
|
|
const collNamePrefix = "array4_";
|
2021-06-15 10:31:10 -04:00
|
|
|
let collCount = 0;
|
|
|
|
|
|
|
|
|
|
let t = db.getCollection(collNamePrefix + collCount++);
|
2010-09-21 13:54:23 -04:00
|
|
|
t.drop();
|
|
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
t.insert({_id: 0, "a": ["1", "2", "3"]});
|
|
|
|
|
t.insert({_id: 1, "a": ["2", "1"]});
|
2010-09-21 13:54:23 -04:00
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
let query = {"a.0": /1/};
|
2010-09-21 13:54:23 -04:00
|
|
|
|
2021-06-15 10:31:10 -04:00
|
|
|
let docs = t.find(query).toArray();
|
|
|
|
|
assert.eq(docs.length, 1, tojson(docs));
|
2010-09-21 13:54:23 -04:00
|
|
|
|
2021-06-15 10:31:10 -04:00
|
|
|
assert.eq(docs[0].a[0], 1, tojson(docs));
|
|
|
|
|
assert.eq(docs[0].a[1], 2, tojson(docs));
|
2010-09-21 13:54:23 -04:00
|
|
|
|
2021-06-15 10:31:10 -04:00
|
|
|
t = db.getCollection(collNamePrefix + collCount++);
|
2010-09-21 13:54:23 -04:00
|
|
|
t.drop();
|
|
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
t.insert({_id: 2, "a": {"0": "1"}});
|
|
|
|
|
t.insert({_id: 3, "a": ["2", "1"]});
|
2010-09-21 13:54:23 -04:00
|
|
|
|
2021-06-15 10:31:10 -04:00
|
|
|
docs = t.find(query).toArray();
|
|
|
|
|
assert.eq(docs.length, 1, tojson(docs));
|
|
|
|
|
assert.eq(docs[0].a[0], 1, tojson(docs));
|
2010-09-21 13:54:23 -04:00
|
|
|
|
2021-06-15 10:31:10 -04:00
|
|
|
t = db.getCollection(collNamePrefix + collCount++);
|
2010-09-21 13:54:23 -04:00
|
|
|
t.drop();
|
|
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
t.insert({_id: 4, "a": ["0", "1", "2", "3", "4", "5", "6", "1", "1", "1", "2", "3", "2", "1"]});
|
|
|
|
|
t.insert({_id: 5, "a": ["2", "1"]});
|
2010-09-21 13:54:23 -04:00
|
|
|
|
2021-06-15 10:31:10 -04:00
|
|
|
query = {
|
2025-08-21 10:17:44 -07:00
|
|
|
"a.12": /2/,
|
2016-03-09 12:17:50 -05:00
|
|
|
};
|
2021-06-15 10:31:10 -04:00
|
|
|
|
|
|
|
|
docs = t.find(query).toArray();
|
|
|
|
|
assert.eq(docs.length, 1, tojson(docs));
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.eq(docs[0].a[0], 0, tojson(docs));
|