summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2021-06-15 10:31:10 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-15 14:58:01 +0000
commitb3f9a51989261ed7f52bc5460bcb1a0dbdd62b0c (patch)
tree39b26ddbce891b811dd43e0018293c6e3191b59c
parent154af4ac2e97f0457a4f88f9af6fc73efe91c057 (diff)
downloadmongo-b3f9a51989261ed7f52bc5460bcb1a0dbdd62b0c.tar.gz
SERVER-57704 clean up array4.js to avoid fast count and to use unique collection names across test cases.
-rw-r--r--jstests/core/array4.js47
1 files changed, 30 insertions, 17 deletions
diff --git a/jstests/core/array4.js b/jstests/core/array4.js
index 55604705264..9a006fa33bc 100644
--- a/jstests/core/array4.js
+++ b/jstests/core/array4.js
@@ -1,34 +1,47 @@
/**
* Basic test for querying on documents containing arrays.
*/
-t = db.array4;
+(function() {
+'use strict';
+
+const collNamePrefix = 'array4_';
+let collCount = 0;
+
+let t = db.getCollection(collNamePrefix + collCount++);
t.drop();
-t.insert({"a": ["1", "2", "3"]});
-t.insert({"a": ["2", "1"]});
+t.insert({_id: 0, 'a': ['1', '2', '3']});
+t.insert({_id: 1, 'a': ['2', '1']});
-var x = {'a.0': /1/};
+let query = {'a.0': /1/};
-assert.eq(t.count(x), 1);
+let docs = t.find(query).toArray();
+assert.eq(docs.length, 1, tojson(docs));
-assert.eq(t.findOne(x).a[0], 1);
-assert.eq(t.findOne(x).a[1], 2);
+assert.eq(docs[0].a[0], 1, tojson(docs));
+assert.eq(docs[0].a[1], 2, tojson(docs));
+t = db.getCollection(collNamePrefix + collCount++);
t.drop();
-t.insert({"a": {"0": "1"}});
-t.insert({"a": ["2", "1"]});
+t.insert({_id: 2, 'a': {'0': '1'}});
+t.insert({_id: 3, 'a': ['2', '1']});
-assert.eq(t.count(x), 1);
-assert.eq(t.findOne(x).a[0], 1);
+docs = t.find(query).toArray();
+assert.eq(docs.length, 1, tojson(docs));
+assert.eq(docs[0].a[0], 1, tojson(docs));
+t = db.getCollection(collNamePrefix + collCount++);
t.drop();
-t.insert({"a": ["0", "1", "2", "3", "4", "5", "6", "1", "1", "1", "2", "3", "2", "1"]});
-t.insert({"a": ["2", "1"]});
+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']});
-x = {
- "a.12": /2/
+query = {
+ 'a.12': /2/
};
-assert.eq(t.count(x), 1);
-assert.eq(t.findOne(x).a[0], 0);
+
+docs = t.find(query).toArray();
+assert.eq(docs.length, 1, tojson(docs));
+assert.eq(docs[0].a[0], 0, tojson(docs));
+}());