2020-08-13 19:13:40 -04:00
|
|
|
/**
|
2021-03-01 13:19:14 -05:00
|
|
|
* Basic test for querying on documents containing arrays.
|
2020-08-13 19:13:40 -04:00
|
|
|
*/
|
2021-06-15 10:31:10 -04:00
|
|
|
(function() {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const collNamePrefix = 'array4_';
|
|
|
|
|
let collCount = 0;
|
|
|
|
|
|
|
|
|
|
let t = db.getCollection(collNamePrefix + collCount++);
|
2010-09-21 13:54:23 -04:00
|
|
|
t.drop();
|
|
|
|
|
|
2021-06-15 10:31:10 -04:00
|
|
|
t.insert({_id: 0, 'a': ['1', '2', '3']});
|
|
|
|
|
t.insert({_id: 1, 'a': ['2', '1']});
|
2010-09-21 13:54:23 -04:00
|
|
|
|
2021-06-15 10:31:10 -04: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();
|
|
|
|
|
|
2021-06-15 10:31:10 -04: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();
|
|
|
|
|
|
2021-06-15 10:31:10 -04: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 = {
|
|
|
|
|
'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));
|
|
|
|
|
assert.eq(docs[0].a[0], 0, tojson(docs));
|
|
|
|
|
}());
|