summaryrefslogtreecommitdiff
path: root/src/mongo/db/index
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2016-08-22 16:41:50 -0400
committerDavid Storch <david.storch@10gen.com>2016-08-23 17:42:08 -0400
commitf3be5348457ff71185ca9fa137ab7c1a8e4761df (patch)
treee2bdc25fab6568d577cb14f9905d593c07ee86e4 /src/mongo/db/index
parent6b5fd115d38582d8b349a5aad2c29867e69dc758 (diff)
downloadmongo-f3be5348457ff71185ca9fa137ab7c1a8e4761df.tar.gz
SERVER-24508 delete BSONObjCmp
Instead, use BSONObj::ComparatorInterface.
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r--src/mongo/db/index/2d_key_generator_test.cpp13
-rw-r--r--src/mongo/db/index/btree_key_generator.h1
-rw-r--r--src/mongo/db/index/btree_key_generator_test.cpp165
-rw-r--r--src/mongo/db/index/expression_keys_private.cpp7
-rw-r--r--src/mongo/db/index/expression_keys_private.h2
-rw-r--r--src/mongo/db/index/external_key_generator.cpp3
-rw-r--r--src/mongo/db/index/hash_key_generator_test.cpp17
-rw-r--r--src/mongo/db/index/index_access_method.cpp10
-rw-r--r--src/mongo/db/index/index_access_method.h6
-rw-r--r--src/mongo/db/index/s2_key_generator_test.cpp51
10 files changed, 143 insertions, 132 deletions
diff --git a/src/mongo/db/index/2d_key_generator_test.cpp b/src/mongo/db/index/2d_key_generator_test.cpp
index 9f6e3405fd1..136c3a5d16c 100644
--- a/src/mongo/db/index/2d_key_generator_test.cpp
+++ b/src/mongo/db/index/2d_key_generator_test.cpp
@@ -35,6 +35,7 @@
#include <algorithm>
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/index/2d_common.h"
#include "mongo/db/index/expression_params.h"
#include "mongo/db/json.h"
@@ -88,11 +89,11 @@ TEST(2dKeyGeneratorTest, TrailingField) {
BSONObj infoObj = fromjson("{key: {a: '2d', b: 1}}");
TwoDIndexingParams params;
ExpressionParams::parseTwoDParams(infoObj, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
std::vector<BSONObj> locs;
ExpressionKeysPrivate::get2DKeys(obj, params, &actualKeys, &locs);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
BSONObj trailingFields = BSON("" << 5);
expectedKeys.insert(make2DKey(params, 0, 0, trailingFields.firstElement()));
@@ -104,11 +105,11 @@ TEST(2dKeyGeneratorTest, ArrayTrailingField) {
BSONObj infoObj = fromjson("{key: {a: '2d', b: 1}}");
TwoDIndexingParams params;
ExpressionParams::parseTwoDParams(infoObj, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
std::vector<BSONObj> locs;
ExpressionKeysPrivate::get2DKeys(obj, params, &actualKeys, &locs);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
BSONObj trailingFields = BSON("" << BSON_ARRAY(5 << 6));
expectedKeys.insert(make2DKey(params, 0, 0, trailingFields.firstElement()));
@@ -120,11 +121,11 @@ TEST(2dKeyGeneratorTest, ArrayOfObjectsTrailingField) {
BSONObj infoObj = fromjson("{key: {a: '2d', 'b.c': 1}}");
TwoDIndexingParams params;
ExpressionParams::parseTwoDParams(infoObj, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
std::vector<BSONObj> locs;
ExpressionKeysPrivate::get2DKeys(obj, params, &actualKeys, &locs);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
BSONObj trailingFields = BSON("" << BSON_ARRAY(5 << 6));
expectedKeys.insert(make2DKey(params, 0, 0, trailingFields.firstElement()));
diff --git a/src/mongo/db/index/btree_key_generator.h b/src/mongo/db/index/btree_key_generator.h
index 76df5e7c810..382a55bc355 100644
--- a/src/mongo/db/index/btree_key_generator.h
+++ b/src/mongo/db/index/btree_key_generator.h
@@ -31,6 +31,7 @@
#include <set>
#include <vector>
+#include "mongo/bson/bsonobj_comparator_interface.h"
#include "mongo/db/index/multikey_paths.h"
#include "mongo/db/jsobj.h"
diff --git a/src/mongo/db/index/btree_key_generator_test.cpp b/src/mongo/db/index/btree_key_generator_test.cpp
index effeb192e9a..d8bb9e64024 100644
--- a/src/mongo/db/index/btree_key_generator_test.cpp
+++ b/src/mongo/db/index/btree_key_generator_test.cpp
@@ -35,6 +35,7 @@
#include <algorithm>
#include <iostream>
+#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/json.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
#include "mongo/unittest/unittest.h"
@@ -124,7 +125,7 @@ bool testKeygen(const BSONObj& kp,
// the indexed fields that would cause the index to be multikey as a result of inserting
// 'actualKeys'.
//
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
keyGen->getKeys(obj, &actualKeys, &actualMultikeyPaths);
@@ -155,7 +156,7 @@ bool testKeygen(const BSONObj& kp,
TEST(BtreeKeyGeneratorTest, GetIdKeyFromObject) {
BSONObj keyPattern = fromjson("{_id: 1}");
BSONObj genKeysFrom = fromjson("{_id: 'foo', b: 4}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 'foo'}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -164,7 +165,7 @@ TEST(BtreeKeyGeneratorTest, GetIdKeyFromObject) {
TEST(BtreeKeyGeneratorTest, GetKeysFromObjectSimple) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{b: 4, a: 5}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 5}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -173,7 +174,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromObjectSimple) {
TEST(BtreeKeyGeneratorTest, GetKeysFromObjectDotted) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: {b: 4}, c: 'foo'}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 4}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -182,7 +183,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromObjectDotted) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArraySimple) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{a: [1, 2, 3]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
expectedKeys.insert(fromjson("{'': 3}"));
@@ -193,7 +194,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArraySimple) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArrayWithIdenticalValues) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{a: [0, 0, 0]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 0}"));
MultikeyPaths expectedMultikeyPaths{{0U}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -202,7 +203,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArrayWithIdenticalValues) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArrayWithEquivalentValues) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{a: [0, NumberInt(0), NumberLong(0)]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 0}"));
MultikeyPaths expectedMultikeyPaths{{0U}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -211,7 +212,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArrayWithEquivalentValues) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArrayFirstElement) {
BSONObj keyPattern = fromjson("{a: 1, b: 1}");
BSONObj genKeysFrom = fromjson("{a: [1, 2, 3], b: 2}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1, '': 2}"));
expectedKeys.insert(fromjson("{'': 2, '': 2}"));
expectedKeys.insert(fromjson("{'': 3, '': 2}"));
@@ -222,7 +223,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArrayFirstElement) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArraySecondElement) {
BSONObj keyPattern = fromjson("{first: 1, a: 1}");
BSONObj genKeysFrom = fromjson("{first: 5, a: [1, 2, 3]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 5, '': 1}"));
expectedKeys.insert(fromjson("{'': 5, '': 2}"));
expectedKeys.insert(fromjson("{'': 5, '': 3}"));
@@ -233,7 +234,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArraySecondElement) {
TEST(BtreeKeyGeneratorTest, GetKeysFromSecondLevelArray) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: {b: [1, 2, 3]}}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
expectedKeys.insert(fromjson("{'': 3}"));
@@ -244,7 +245,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromSecondLevelArray) {
TEST(BtreeKeyGeneratorTest, GetKeysFromParallelArraysBasic) {
BSONObj keyPattern = fromjson("{'a': 1, 'b': 1}");
BSONObj genKeysFrom = fromjson("{a: [1, 2, 3], b: [1, 2, 3]}}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths(keyPattern.nFields());
ASSERT_THROWS(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths),
UserException);
@@ -253,7 +254,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromParallelArraysBasic) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArraySubobjectBasic) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [{b:1,c:4}, {b:2,c:4}, {b:3,c:4}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
expectedKeys.insert(fromjson("{'': 3}"));
@@ -264,7 +265,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArraySubobjectBasic) {
TEST(BtreeKeyGeneratorTest, GetKeysFromSubobjectWithArrayOfSubobjects) {
BSONObj keyPattern = fromjson("{'a.b.c': 1}");
BSONObj genKeysFrom = fromjson("{a: {b: [{c: 1}, {c: 2}]}}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
MultikeyPaths expectedMultikeyPaths{{1U}};
@@ -274,7 +275,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromSubobjectWithArrayOfSubobjects) {
TEST(BtreeKeyGeneratorTest, GetKeysArraySubobjectCompoundIndex) {
BSONObj keyPattern = fromjson("{'a.b': 1, d: 99}");
BSONObj genKeysFrom = fromjson("{a: [{b:1,c:4}, {b:2,c:4}, {b:3,c:4}], d: 99}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1, '': 99}"));
expectedKeys.insert(fromjson("{'': 2, '': 99}"));
expectedKeys.insert(fromjson("{'': 3, '': 99}"));
@@ -285,7 +286,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysArraySubobjectCompoundIndex) {
TEST(BtreeKeyGeneratorTest, GetKeysArraySubobjectSingleMissing) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [{foo: 41}, {b:1,c:4}, {b:2,c:4}, {b:3,c:4}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
@@ -297,7 +298,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysArraySubobjectSingleMissing) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArraySubobjectMissing) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [{foo: 41}, {foo: 41}, {foo: 41}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
MultikeyPaths expectedMultikeyPaths{{0U}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -306,7 +307,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArraySubobjectMissing) {
TEST(BtreeKeyGeneratorTest, GetKeysMissingField) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{b: 1}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -315,7 +316,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysMissingField) {
TEST(BtreeKeyGeneratorTest, GetKeysSubobjectMissing) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [1, 2]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
MultikeyPaths expectedMultikeyPaths{{0U}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -324,7 +325,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysSubobjectMissing) {
TEST(BtreeKeyGeneratorTest, GetKeysFromCompound) {
BSONObj keyPattern = fromjson("{x: 1, y: 1}");
BSONObj genKeysFrom = fromjson("{x: 'a', y: 'b'}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 'a', '': 'b'}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}, std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -333,7 +334,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromCompound) {
TEST(BtreeKeyGeneratorTest, GetKeysFromCompoundMissing) {
BSONObj keyPattern = fromjson("{x: 1, y: 1}");
BSONObj genKeysFrom = fromjson("{x: 'a'}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 'a', '': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}, std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -342,7 +343,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromCompoundMissing) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArraySubelementComplex) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a:[{b:[2]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 2}"));
// Both the 'a' and 'a.b' arrays contain a single element.
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
@@ -352,7 +353,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArraySubelementComplex) {
TEST(BtreeKeyGeneratorTest, GetKeysFromParallelArraysComplex) {
BSONObj keyPattern = fromjson("{'a.b': 1, 'a.c': 1}");
BSONObj genKeysFrom = fromjson("{a:[{b:[1],c:[2]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths(keyPattern.nFields());
ASSERT_THROWS(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths),
UserException);
@@ -361,7 +362,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromParallelArraysComplex) {
TEST(BtreeKeyGeneratorTest, GetKeysAlternateMissing) {
BSONObj keyPattern = fromjson("{'a.b': 1, 'a.c': 1}");
BSONObj genKeysFrom = fromjson("{a:[{b:1},{c:2}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null, '': 2}"));
expectedKeys.insert(fromjson("{'': 1, '': null}"));
MultikeyPaths expectedMultikeyPaths{{0U}, {0U}};
@@ -371,7 +372,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysAlternateMissing) {
TEST(BtreeKeyGeneratorTest, GetKeysFromMultiComplex) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a:[{b:1},{b:[1,2,3]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
expectedKeys.insert(fromjson("{'': 3}"));
@@ -382,7 +383,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromMultiComplex) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArrayOfSubobjectsWithArrayValues) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [{b: [1, 2]}, {b: [2, 3]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
expectedKeys.insert(fromjson("{'': 3}"));
@@ -393,7 +394,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArrayOfSubobjectsWithArrayValues) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArrayOfSubobjectsWithNonDistinctArrayValues) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [{b: [1, 2, 3]}, {b: [2]}, {b: [3, 1]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
expectedKeys.insert(fromjson("{'': 3}"));
@@ -404,7 +405,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArrayOfSubobjectsWithNonDistinctArrayValu
TEST(BtreeKeyGeneratorTest, GetKeysArrayEmpty) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{a:[1,2]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
MultikeyPaths expectedMultikeyPaths{{0U}};
@@ -430,7 +431,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysArrayEmpty) {
TEST(BtreeKeyGeneratorTest, GetKeysFromDoubleArray) {
BSONObj keyPattern = fromjson("{a: 1, a: 1}");
BSONObj genKeysFrom = fromjson("{a:[1,2]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1, '': 1}"));
expectedKeys.insert(fromjson("{'': 2, '': 2}"));
MultikeyPaths expectedMultikeyPaths{{0U}, {0U}};
@@ -440,7 +441,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromDoubleArray) {
TEST(BtreeKeyGeneratorTest, GetKeysFromDoubleEmptyArray) {
BSONObj keyPattern = fromjson("{a: 1, a: 1}");
BSONObj genKeysFrom = fromjson("{a:[]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': undefined, '': undefined}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}, std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -449,7 +450,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromDoubleEmptyArray) {
TEST(BtreeKeyGeneratorTest, GetKeysFromMultiEmptyArray) {
BSONObj keyPattern = fromjson("{a: 1, b: 1}");
BSONObj genKeysFrom = fromjson("{a: 1, b: [1, 2]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1, '': 1}"));
expectedKeys.insert(fromjson("{'': 1, '': 2}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}, {0U}};
@@ -470,7 +471,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromMultiEmptyArray) {
TEST(BtreeKeyGeneratorTest, GetKeysFromNestedEmptyArray) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a:[]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -479,7 +480,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromNestedEmptyArray) {
TEST(BtreeKeyGeneratorTest, GetKeysFromMultiNestedEmptyArray) {
BSONObj keyPattern = fromjson("{'a.b': 1, 'a.c': 1}");
BSONObj genKeysFrom = fromjson("{a:[]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null, '': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}, std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -488,7 +489,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromMultiNestedEmptyArray) {
TEST(BtreeKeyGeneratorTest, GetKeysFromUnevenNestedEmptyArray) {
BSONObj keyPattern = fromjson("{'a': 1, 'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a:[]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': undefined, '': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}, std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -507,7 +508,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromUnevenNestedEmptyArray) {
TEST(BtreeKeyGeneratorTest, GetKeysFromReverseUnevenNestedEmptyArray) {
BSONObj keyPattern = fromjson("{'a.b': 1, 'a': 1}");
BSONObj genKeysFrom = fromjson("{a:[]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null, '': undefined}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}, std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -517,7 +518,7 @@ TEST(BtreeKeyGeneratorTest, SparseReverseUnevenNestedEmptyArray) {
const bool sparse = true;
BSONObj keyPattern = fromjson("{'a.b': 1, 'a': 1}");
BSONObj genKeysFrom = fromjson("{a:[]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null, '': undefined}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}, std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths, sparse));
@@ -527,7 +528,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromSparseEmptyArray) {
const bool sparse = true;
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a:1}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths, sparse));
@@ -542,7 +543,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromSparseEmptyArraySecond) {
const bool sparse = true;
BSONObj keyPattern = fromjson("{z: 1, 'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a:1}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}, std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths, sparse));
@@ -557,7 +558,7 @@ TEST(BtreeKeyGeneratorTest, SparseNonObjectMissingNestedField) {
const bool sparse = true;
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a:[]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths, sparse));
@@ -574,7 +575,7 @@ TEST(BtreeKeyGeneratorTest, SparseNonObjectMissingNestedField) {
TEST(BtreeKeyGeneratorTest, GetKeysFromIndexedArrayIndex) {
BSONObj keyPattern = fromjson("{'a.0': 1}");
BSONObj genKeysFrom = fromjson("{a:[1]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -612,7 +613,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromIndexedArrayIndex) {
TEST(BtreeKeyGeneratorTest, GetKeysFromDoubleIndexedArrayIndex) {
BSONObj keyPattern = fromjson("{'a.0.0': 1}");
BSONObj genKeysFrom = fromjson("{a:[[1]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -636,7 +637,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromDoubleIndexedArrayIndex) {
TEST(BtreeKeyGeneratorTest, GetKeysFromObjectWithinArray) {
BSONObj keyPattern = fromjson("{'a.0.b': 1}");
BSONObj genKeysFrom = fromjson("{a:[{b:1}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -675,7 +676,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromObjectWithinArray) {
TEST(BtreeKeyGeneratorTest, GetKeysFromArrayWithinObjectWithinArray) {
BSONObj keyPattern = fromjson("{'a.0.b.0': 1}");
BSONObj genKeysFrom = fromjson("{a:[{b:[1]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -684,7 +685,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFromArrayWithinObjectWithinArray) {
TEST(BtreeKeyGeneratorTest, ParallelArraysInNestedObjects) {
BSONObj keyPattern = fromjson("{'a.a': 1, 'b.a': 1}");
BSONObj genKeysFrom = fromjson("{a:{a:[1]}, b:{a:[1]}}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths(keyPattern.nFields());
ASSERT_THROWS(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths),
UserException);
@@ -693,7 +694,7 @@ TEST(BtreeKeyGeneratorTest, ParallelArraysInNestedObjects) {
TEST(BtreeKeyGeneratorTest, ParallelArraysUneven) {
BSONObj keyPattern = fromjson("{'b.a': 1, 'a': 1}");
BSONObj genKeysFrom = fromjson("{b:{a:[1]}, a:[1,2]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths(keyPattern.nFields());
ASSERT_THROWS(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths),
UserException);
@@ -702,7 +703,7 @@ TEST(BtreeKeyGeneratorTest, ParallelArraysUneven) {
TEST(BtreeKeyGeneratorTest, MultipleArraysNotParallel) {
BSONObj keyPattern = fromjson("{'a.b.c': 1}");
BSONObj genKeysFrom = fromjson("{a: [1, 2, {b: {c: [3, 4]}}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
expectedKeys.insert(fromjson("{'': 3}"));
expectedKeys.insert(fromjson("{'': 4}"));
@@ -713,7 +714,7 @@ TEST(BtreeKeyGeneratorTest, MultipleArraysNotParallel) {
TEST(BtreeKeyGeneratorTest, MultipleArraysNotParallelCompound) {
BSONObj keyPattern = fromjson("{'a.b.c': 1, 'a.b.d': 1}");
BSONObj genKeysFrom = fromjson("{a: [1, 2, {b: {c: [3, 4], d: 5}}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null, '': null}"));
expectedKeys.insert(fromjson("{'': 3, '': 5}"));
expectedKeys.insert(fromjson("{'': 4, '': 5}"));
@@ -724,7 +725,7 @@ TEST(BtreeKeyGeneratorTest, MultipleArraysNotParallelCompound) {
TEST(BtreeKeyGeneratorTest, GetKeysComplexNestedArrays) {
BSONObj keyPattern = fromjson("{'a.b.c.d': 1, 'a.g': 1, 'a.b.f': 1, 'a.b.c': 1, 'a.b.e': 1}");
BSONObj genKeysFrom = fromjson("{a: [1, {b: [2, {c: [3, {d: 1}], e: 4}, 5, {f: 6}], g: 7}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'':null, '':null, '':null, '':null, '':null}"));
expectedKeys.insert(fromjson("{'':null, '':7, '':null, '':null, '':null}"));
expectedKeys.insert(fromjson("{'':null, '':7, '':null, '':3, '':4}"));
@@ -738,7 +739,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysComplexNestedArrays) {
TEST(BtreeKeyGeneratorTest, GetKeys2DArray) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{a: [[2]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': [2]}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -749,7 +750,7 @@ TEST(BtreeKeyGeneratorTest, GetKeys2DArray) {
TEST(BtreeKeyGeneratorTest, GetKeysParallelEmptyArrays) {
BSONObj keyPattern = fromjson("{a: 1, b: 1}");
BSONObj genKeysFrom = fromjson("{a: [], b: []}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths(keyPattern.nFields());
ASSERT_THROWS(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths),
UserException);
@@ -758,7 +759,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysParallelEmptyArrays) {
TEST(BtreeKeyGeneratorTest, GetKeysParallelArraysOneArrayEmpty) {
BSONObj keyPattern = fromjson("{a: 1, b: 1}");
BSONObj genKeysFrom = fromjson("{a: [], b: [1, 2, 3]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths(keyPattern.nFields());
ASSERT_THROWS(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths),
UserException);
@@ -767,7 +768,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysParallelArraysOneArrayEmpty) {
TEST(BtreeKeyGeneratorTest, GetKeysParallelArraysOneArrayEmptyNested) {
BSONObj keyPattern = fromjson("{'a.b.c': 1, 'a.b.d': 1}");
BSONObj genKeysFrom = fromjson("{a: [{b: [{c: [1, 2, 3], d: []}]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths(keyPattern.nFields());
ASSERT_THROWS(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths),
UserException);
@@ -777,7 +778,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysParallelArraysOneArrayEmptyNested) {
TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternMissingElement) {
BSONObj keyPattern = fromjson("{'a.2': 1}");
BSONObj genKeysFrom = fromjson("{a: [{'2': 5}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 5}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -787,7 +788,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternMissingElement) {
TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray) {
BSONObj keyPattern = fromjson("{'a.2': 1}");
BSONObj genKeysFrom = fromjson("{a: [[1, 2, 5]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -797,7 +798,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray) {
TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray2) {
BSONObj keyPattern = fromjson("{'a.2': 1}");
BSONObj genKeysFrom = fromjson("{a: [[1, 2, 5], [3, 4, 6], [0, 1, 2]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': [0, 1, 2]}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -807,7 +808,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray2) {
TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray3) {
BSONObj keyPattern = fromjson("{'a.2': 1}");
BSONObj genKeysFrom = fromjson("{a: [{'0': 1, '1': 2, '2': 5}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 5}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -817,7 +818,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray3) {
TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray4) {
BSONObj keyPattern = fromjson("{'a.b.2': 1}");
BSONObj genKeysFrom = fromjson("{a: [{b: [[1, 2, 5]]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -827,7 +828,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray4) {
TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray5) {
BSONObj keyPattern = fromjson("{'a.2': 1}");
BSONObj genKeysFrom = fromjson("{a: [[1, 2, 5], {'2': 6}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
expectedKeys.insert(fromjson("{'': 6}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{0U}};
@@ -837,7 +838,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysPositionalKeyPatternNestedArray5) {
TEST(BtreeKeyGeneratorTest, GetNullKeyNestedArray) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [[1, 2, 5]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -846,7 +847,7 @@ TEST(BtreeKeyGeneratorTest, GetNullKeyNestedArray) {
TEST(BtreeKeyGeneratorTest, GetKeysUnevenNestedArrays) {
BSONObj keyPattern = fromjson("{a: 1, 'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [1, {b: [2, 3, 4]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1, '': null}"));
expectedKeys.insert(fromjson("{'': {b:[2,3,4]}, '': 2}"));
expectedKeys.insert(fromjson("{'': {b:[2,3,4]}, '': 3}"));
@@ -860,7 +861,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysUnevenNestedArrays) {
TEST(BtreeKeyGeneratorTest, GetKeysRepeatedFieldName) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{a: 2, a: 3}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 2}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -871,7 +872,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysRepeatedFieldName) {
TEST(BtreeKeyGeneratorTest, GetKeysEmptyPathPiece) {
BSONObj keyPattern = fromjson("{'a..c': 1}");
BSONObj genKeysFrom = fromjson("{a: {'': [{c: 1}, {c: 2}]}}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
MultikeyPaths expectedMultikeyPaths{{1U}};
@@ -884,7 +885,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysLastPathPieceEmpty) {
BSONObj keyPattern = fromjson("{'a.': 1}");
BSONObj genKeysFrom = fromjson("{a: 2}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 2}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -898,7 +899,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysLastPathPieceEmpty) {
TEST(BtreeKeyGeneratorTest, GetKeysFirstPathPieceEmpty) {
BSONObj keyPattern = fromjson("{'.a': 1}");
BSONObj genKeysFrom = fromjson("{a: 2}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -907,7 +908,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFirstPathPieceEmpty) {
TEST(BtreeKeyGeneratorTest, GetKeysFirstPathPieceEmpty2) {
BSONObj keyPattern = fromjson("{'.a': 1}");
BSONObj genKeysFrom = fromjson("{'': [{a: [1, 2, 3]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
expectedKeys.insert(fromjson("{'': 3}"));
@@ -918,7 +919,7 @@ TEST(BtreeKeyGeneratorTest, GetKeysFirstPathPieceEmpty2) {
TEST(BtreeKeyGeneratorTest, PositionalKeyPatternParallelArrays) {
BSONObj keyPattern = fromjson("{a: 1, 'b.0': 1}");
BSONObj genKeysFrom = fromjson("{a: [1], b: [2]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths expectedMultikeyPaths(keyPattern.nFields());
ASSERT_THROWS(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths),
UserException);
@@ -927,7 +928,7 @@ TEST(BtreeKeyGeneratorTest, PositionalKeyPatternParallelArrays) {
TEST(BtreeKeyGeneratorTest, KeyPattern_a_0_b_Extracts_b_ElementInsideSingleton2DArray) {
BSONObj keyPattern = fromjson("{'a.0.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [[{b: 1}]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -936,7 +937,7 @@ TEST(BtreeKeyGeneratorTest, KeyPattern_a_0_b_Extracts_b_ElementInsideSingleton2D
TEST(BtreeKeyGeneratorTest, KeyPattern_a_0_0_b_Extracts_b_ElementInsideSingleton2DArray) {
BSONObj keyPattern = fromjson("{'a.0.0.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [[{b: 1}]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -946,7 +947,7 @@ TEST(BtreeKeyGeneratorTest,
KeyPattern_a_0_0_b_ExtractsEachValueFrom_b_ArrayInsideSingleton2DArray) {
BSONObj keyPattern = fromjson("{'a.0.0.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [[{b: [1, 2, 3]}]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
expectedKeys.insert(fromjson("{'': 3}"));
@@ -957,7 +958,7 @@ TEST(BtreeKeyGeneratorTest,
TEST(BtreeKeyGeneratorTest, KeyPattern_a_0_0_b_Extracts_b_ElementInsideSingleton3DArray) {
BSONObj keyPattern = fromjson("{'a.0.0.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [[[ {b: 1} ]]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -966,7 +967,7 @@ TEST(BtreeKeyGeneratorTest, KeyPattern_a_0_0_b_Extracts_b_ElementInsideSingleton
TEST(BtreeKeyGeneratorTest, KeyPattern_a_0_0_b_ExtractsEach_b_ElementInside3DArray) {
BSONObj keyPattern = fromjson("{'a.0.0.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [[[{b: 1}, {b: 2}, {b: 3}]]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 1}"));
expectedKeys.insert(fromjson("{'': 2}"));
expectedKeys.insert(fromjson("{'': 3}"));
@@ -977,7 +978,7 @@ TEST(BtreeKeyGeneratorTest, KeyPattern_a_0_0_b_ExtractsEach_b_ElementInside3DArr
TEST(BtreeKeyGeneratorTest, KeyPattern_a_0_0_b_ExtractsNullFrom4DArray) {
BSONObj keyPattern = fromjson("{'a.0.0.b': 1}");
BSONObj genKeysFrom = fromjson("{a: [[[[ {b: 1} ]]]]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': null}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -986,7 +987,7 @@ TEST(BtreeKeyGeneratorTest, KeyPattern_a_0_0_b_ExtractsNullFrom4DArray) {
TEST(BtreeKeyGeneratorTest, PositionalKeyPatternNestedArrays5) {
BSONObj keyPattern = fromjson("{'a.b.1': 1}");
BSONObj genKeysFrom = fromjson("{a: [{b: [1, 2]}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 2}"));
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
ASSERT(testKeygen(keyPattern, genKeysFrom, expectedKeys, expectedMultikeyPaths));
@@ -996,7 +997,7 @@ TEST(BtreeKeyGeneratorTest, PositionalKeyPatternNestedArrays5) {
TEST(BtreeKeyGeneratorTest, PositionalKeyPatternNestedArrays6) {
BSONObj keyPattern = fromjson("{'a': 1, 'a.b': 1, 'a.0.b':1, 'a.b.0': 1, 'a.0.b.0': 1}");
BSONObj genKeysFrom = fromjson("{a: [{b: [1,2]}, {b: 3}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': {b:3}, '': 3, '': 1, '': null, '': 1}"));
expectedKeys.insert(fromjson("{'': {b:3}, '': 3, '': 2, '': null, '': 1}"));
expectedKeys.insert(fromjson("{'': {b:[1,2]}, '': 1, '': 1, '': 1, '': 1}"));
@@ -1009,7 +1010,7 @@ TEST(BtreeKeyGeneratorTest, PositionalKeyPatternNestedArrays6) {
TEST(BtreeKeyGeneratorTest, PositionalKeyPatternNestedArrays7) {
BSONObj keyPattern = fromjson("{'a': 1, 'a.b': 1, 'a.0.b':1, 'a.b.0': 1, 'a.0.b.0': 1}");
BSONObj genKeysFrom = fromjson("{a: [{b: [1,2]}, {b: {'0': 3}}]}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': {b:{'0':3}}, '': {'0':3}, '': 1, '': 3, '': 1}"));
expectedKeys.insert(fromjson("{'': {b:{'0':3}}, '': {'0':3}, '': 2, '': 3, '': 1}"));
expectedKeys.insert(fromjson("{'': {b:[1,2]}, '': 1, '': 1, '': 1, '': 1}"));
@@ -1021,7 +1022,7 @@ TEST(BtreeKeyGeneratorTest, PositionalKeyPatternNestedArrays7) {
TEST(BtreeKeyGeneratorTest, GetCollationAwareIdKeyFromObject) {
BSONObj keyPattern = fromjson("{_id: 1}");
BSONObj genKeysFrom = fromjson("{_id: 'foo', b: 4}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 'oof'}"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
@@ -1032,7 +1033,7 @@ TEST(BtreeKeyGeneratorTest, GetCollationAwareIdKeyFromObject) {
TEST(BtreeKeyGeneratorTest, GetCollationAwareKeysFromObjectSimple) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{b: 4, a: 'foo'}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 'oof'}"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
@@ -1043,7 +1044,7 @@ TEST(BtreeKeyGeneratorTest, GetCollationAwareKeysFromObjectSimple) {
TEST(BtreeKeyGeneratorTest, GetCollationAwareKeysFromObjectDotted) {
BSONObj keyPattern = fromjson("{'a.b': 1}");
BSONObj genKeysFrom = fromjson("{a: {b: 'foo'}, c: 4}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 'oof'}"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
@@ -1054,7 +1055,7 @@ TEST(BtreeKeyGeneratorTest, GetCollationAwareKeysFromObjectDotted) {
TEST(BtreeKeyGeneratorTest, GetCollationAwareKeysFromArraySimple) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{a: ['foo', 'bar', 'baz']}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 'oof'}"));
expectedKeys.insert(fromjson("{'': 'rab'}"));
expectedKeys.insert(fromjson("{'': 'zab'}"));
@@ -1067,7 +1068,7 @@ TEST(BtreeKeyGeneratorTest, GetCollationAwareKeysFromArraySimple) {
TEST(BtreeKeyGeneratorTest, CollatorDoesNotAffectNonStringIdKey) {
BSONObj keyPattern = fromjson("{_id: 1}");
BSONObj genKeysFrom = fromjson("{_id: 5, b: 4}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 5}"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
@@ -1078,7 +1079,7 @@ TEST(BtreeKeyGeneratorTest, CollatorDoesNotAffectNonStringIdKey) {
TEST(BtreeKeyGeneratorTest, CollatorDoesNotAffectNonStringKeys) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{b: 4, a: 5}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': 5}"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
@@ -1089,7 +1090,7 @@ TEST(BtreeKeyGeneratorTest, CollatorDoesNotAffectNonStringKeys) {
TEST(BtreeKeyGeneratorTest, GetCollationAwareKeysFromNestedObject) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{b: 4, a: {c: 'foo'}}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': {c: 'oof'}}"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
@@ -1100,7 +1101,7 @@ TEST(BtreeKeyGeneratorTest, GetCollationAwareKeysFromNestedObject) {
TEST(BtreeKeyGeneratorTest, GetCollationAwareKeysFromNestedArray) {
BSONObj keyPattern = fromjson("{a: 1}");
BSONObj genKeysFrom = fromjson("{b: 4, a: {c: ['foo', 'bar', 'baz']}}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(fromjson("{'': {c: ['oof', 'rab', 'zab']}}"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
MultikeyPaths expectedMultikeyPaths{std::set<size_t>{}};
diff --git a/src/mongo/db/index/expression_keys_private.cpp b/src/mongo/db/index/expression_keys_private.cpp
index 89f8614f0b2..00edf43e3ce 100644
--- a/src/mongo/db/index/expression_keys_private.cpp
+++ b/src/mongo/db/index/expression_keys_private.cpp
@@ -32,6 +32,7 @@
#include <utility>
+#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/field_ref.h"
#include "mongo/db/fts/fts_index_format.h"
@@ -460,7 +461,7 @@ void ExpressionKeysPrivate::getS2Keys(const BSONObj& obj,
const S2IndexingParams& params,
BSONObjSet* keys,
MultikeyPaths* multikeyPaths) {
- BSONObjSet keysToAdd;
+ BSONObjSet keysToAdd = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
// Does one of our documents have a geo field?
bool haveGeoField = false;
@@ -490,7 +491,7 @@ void ExpressionKeysPrivate::getS2Keys(const BSONObj& obj,
// (b) the last component of the indexed path ever refers to GeoJSON data that requires
// multiple cells for its covering.
bool lastPathComponentCausesIndexToBeMultikey;
- BSONObjSet keysForThisField;
+ BSONObjSet keysForThisField = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
if (IndexNames::GEO_2DSPHERE == keyElem.valuestr()) {
if (params.indexVersion >= S2_INDEX_VERSION_2) {
// For >= V2,
@@ -546,7 +547,7 @@ void ExpressionKeysPrivate::getS2Keys(const BSONObj& obj,
continue;
}
- BSONObjSet updatedKeysToAdd;
+ BSONObjSet updatedKeysToAdd = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
for (BSONObjSet::const_iterator it = keysToAdd.begin(); it != keysToAdd.end(); ++it) {
for (BSONObjSet::const_iterator newIt = keysForThisField.begin();
newIt != keysForThisField.end();
diff --git a/src/mongo/db/index/expression_keys_private.h b/src/mongo/db/index/expression_keys_private.h
index a9b032ea97d..cbb8c9508ee 100644
--- a/src/mongo/db/index/expression_keys_private.h
+++ b/src/mongo/db/index/expression_keys_private.h
@@ -30,8 +30,8 @@
#include <vector>
-#include "mongo/bson/bsonmisc.h"
#include "mongo/bson/bsonobj.h"
+#include "mongo/bson/bsonobj_comparator_interface.h"
#include "mongo/db/hasher.h"
#include "mongo/db/index/multikey_paths.h"
diff --git a/src/mongo/db/index/external_key_generator.cpp b/src/mongo/db/index/external_key_generator.cpp
index 192354dc7eb..ed62b1afe74 100644
--- a/src/mongo/db/index/external_key_generator.cpp
+++ b/src/mongo/db/index/external_key_generator.cpp
@@ -31,6 +31,7 @@
#include <cmath>
#include <string>
+#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/fts/fts_spec.h"
#include "mongo/db/index/2d_common.h"
#include "mongo/db/index/btree_key_generator.h"
@@ -194,7 +195,7 @@ int keyV1Size(const BSONObj& obj) {
} // namespace
bool isAnyIndexKeyTooLarge(const BSONObj& index, const BSONObj& doc) {
- BSONObjSet keys;
+ BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
getKeysForUpgradeChecking(index, doc, &keys);
int largestKeySize = 0;
diff --git a/src/mongo/db/index/hash_key_generator_test.cpp b/src/mongo/db/index/hash_key_generator_test.cpp
index a6f6600449a..07436bda0fd 100644
--- a/src/mongo/db/index/hash_key_generator_test.cpp
+++ b/src/mongo/db/index/hash_key_generator_test.cpp
@@ -35,6 +35,7 @@
#include <algorithm>
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/hasher.h"
#include "mongo/db/json.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
@@ -84,13 +85,13 @@ BSONObj makeHashKey(BSONElement elt) {
TEST(HashKeyGeneratorTest, CollationAppliedBeforeHashing) {
BSONObj obj = fromjson("{a: 'string'}");
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionKeysPrivate::getHashKeys(
obj, "a", kHashSeed, kHashVersion, false, &collator, &actualKeys);
BSONObj backwardsObj = fromjson("{a: 'gnirts'}");
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(makeHashKey(backwardsObj["a"]));
ASSERT(assertKeysetsEqual(expectedKeys, actualKeys));
@@ -98,12 +99,12 @@ TEST(HashKeyGeneratorTest, CollationAppliedBeforeHashing) {
TEST(HashKeyGeneratorTest, CollationDoesNotAffectNonStringFields) {
BSONObj obj = fromjson("{a: 5}");
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionKeysPrivate::getHashKeys(
obj, "a", kHashSeed, kHashVersion, false, &collator, &actualKeys);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(makeHashKey(obj["a"]));
ASSERT(assertKeysetsEqual(expectedKeys, actualKeys));
@@ -112,12 +113,12 @@ TEST(HashKeyGeneratorTest, CollationDoesNotAffectNonStringFields) {
TEST(HashKeyGeneratorTest, CollatorAppliedBeforeHashingNestedObject) {
BSONObj obj = fromjson("{a: {b: 'string'}}");
BSONObj backwardsObj = fromjson("{a: {b: 'gnirts'}}");
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionKeysPrivate::getHashKeys(
obj, "a", kHashSeed, kHashVersion, false, &collator, &actualKeys);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(makeHashKey(backwardsObj["a"]));
ASSERT(assertKeysetsEqual(expectedKeys, actualKeys));
@@ -125,11 +126,11 @@ TEST(HashKeyGeneratorTest, CollatorAppliedBeforeHashingNestedObject) {
TEST(HashKeyGeneratorTest, NoCollation) {
BSONObj obj = fromjson("{a: 'string'}");
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
ExpressionKeysPrivate::getHashKeys(
obj, "a", kHashSeed, kHashVersion, false, nullptr, &actualKeys);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(makeHashKey(obj["a"]));
ASSERT(assertKeysetsEqual(expectedKeys, actualKeys));
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp
index 93decde8b15..86c045c0257 100644
--- a/src/mongo/db/index/index_access_method.cpp
+++ b/src/mongo/db/index/index_access_method.cpp
@@ -123,7 +123,7 @@ Status IndexAccessMethod::insert(OperationContext* txn,
int64_t* numInserted) {
invariant(numInserted);
*numInserted = 0;
- BSONObjSet keys;
+ BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths multikeyPaths;
// Delegate to the subclass.
getKeys(obj, &keys, &multikeyPaths);
@@ -201,7 +201,7 @@ Status IndexAccessMethod::remove(OperationContext* txn,
int64_t* numDeleted) {
invariant(numDeleted);
*numDeleted = 0;
- BSONObjSet keys;
+ BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
// There's no need to compute the prefixes of the indexed fields that cause the index to be
// multikey when removing a document since the index metadata isn't updated when keys are
// deleted.
@@ -221,7 +221,7 @@ Status IndexAccessMethod::initializeAsEmpty(OperationContext* txn) {
}
Status IndexAccessMethod::touch(OperationContext* txn, const BSONObj& obj) {
- BSONObjSet keys;
+ BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
// There's no need to compute the prefixes of the indexed fields that cause the index to be
// multikey when paging a document's index entries into memory.
MultikeyPaths* multikeyPaths = nullptr;
@@ -242,7 +242,7 @@ Status IndexAccessMethod::touch(OperationContext* txn) const {
RecordId IndexAccessMethod::findSingle(OperationContext* txn, const BSONObj& key) const {
// Generate the key for this index.
- BSONObjSet keys;
+ BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths* multikeyPaths = nullptr;
getKeys(key, &keys, multikeyPaths);
invariant(keys.size() == 1);
@@ -410,7 +410,7 @@ Status IndexAccessMethod::BulkBuilder::insert(OperationContext* txn,
const RecordId& loc,
const InsertDeleteOptions& options,
int64_t* numInserted) {
- BSONObjSet keys;
+ BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths multikeyPaths;
_real->getKeys(obj, &keys, &multikeyPaths);
diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h
index 35455f5425c..b3647ed3a09 100644
--- a/src/mongo/db/index/index_access_method.h
+++ b/src/mongo/db/index/index_access_method.h
@@ -32,6 +32,7 @@
#include <memory>
#include "mongo/base/disallow_copying.h"
+#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/operation_context.h"
@@ -295,7 +296,10 @@ private:
* validateUpdate fills out the UpdateStatus and update actually applies it.
*/
class UpdateTicket {
- // No public interface
+public:
+ UpdateTicket()
+ : oldKeys(SimpleBSONObjComparator::kInstance.makeBSONObjSet()), newKeys(oldKeys) {}
+
private:
friend class IndexAccessMethod;
diff --git a/src/mongo/db/index/s2_key_generator_test.cpp b/src/mongo/db/index/s2_key_generator_test.cpp
index fc126c0272c..82fdbd9c605 100644
--- a/src/mongo/db/index/s2_key_generator_test.cpp
+++ b/src/mongo/db/index/s2_key_generator_test.cpp
@@ -35,6 +35,7 @@
#include <algorithm>
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/index/expression_params.h"
#include "mongo/db/index/s2_common.h"
#include "mongo/db/json.h"
@@ -121,7 +122,7 @@ long long getCellID(int x, int y, bool multiPoint = false) {
const CollatorInterface* collator = nullptr;
ExpressionParams::initialize2dsphereParams(infoObj, collator, &params);
- BSONObjSet keys;
+ BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
// There's no need to compute the prefixes of the indexed fields that cause the index to be
// multikey when computing the cell id of the geo field.
MultikeyPaths* multikeyPaths = nullptr;
@@ -142,12 +143,12 @@ TEST(S2KeyGeneratorTest, GetS2KeysFromSubobjectWithArrayOfGeoAndNonGeoSubobjects
CollatorInterfaceMock* collator = nullptr;
ExpressionParams::initialize2dsphereParams(infoObj, collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(
genKeysFrom, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << 1 << "" << getCellID(0, 0)));
expectedKeys.insert(BSON("" << 1 << "" << getCellID(3, 3)));
expectedKeys.insert(BSON("" << 2 << "" << getCellID(0, 0)));
@@ -168,12 +169,12 @@ TEST(S2KeyGeneratorTest, GetS2KeysFromArrayOfNonGeoSubobjectsWithArrayValues) {
CollatorInterfaceMock* collator = nullptr;
ExpressionParams::initialize2dsphereParams(infoObj, collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(
genKeysFrom, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << 1 << "" << getCellID(0, 0)));
expectedKeys.insert(BSON("" << 2 << "" << getCellID(0, 0)));
expectedKeys.insert(BSON("" << 3 << "" << getCellID(0, 0)));
@@ -191,13 +192,13 @@ TEST(S2KeyGeneratorTest, GetS2KeysFromMultiPointInGeoField) {
CollatorInterfaceMock* collator = nullptr;
ExpressionParams::initialize2dsphereParams(infoObj, collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(
genKeysFrom, keyPattern, params, &actualKeys, &actualMultikeyPaths);
const bool multiPoint = true;
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << 1 << "" << getCellID(0, 0, multiPoint)));
expectedKeys.insert(BSON("" << 1 << "" << getCellID(1, 0, multiPoint)));
expectedKeys.insert(BSON("" << 1 << "" << getCellID(1, 1, multiPoint)));
@@ -214,11 +215,11 @@ TEST(S2KeyGeneratorTest, CollationAppliedToNonGeoStringFieldAfterGeoField) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionParams::initialize2dsphereParams(infoObj, &collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(obj, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << getCellID(0, 0) << ""
<< "gnirts"));
@@ -235,11 +236,11 @@ TEST(S2KeyGeneratorTest, CollationAppliedToNonGeoStringFieldBeforeGeoField) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionParams::initialize2dsphereParams(infoObj, &collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(obj, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON(""
<< "gnirts"
<< ""
@@ -258,11 +259,11 @@ TEST(S2KeyGeneratorTest, CollationAppliedToAllNonGeoStringFields) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionParams::initialize2dsphereParams(infoObj, &collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(obj, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON(""
<< "gnirts"
<< ""
@@ -284,11 +285,11 @@ TEST(S2KeyGeneratorTest, CollationAppliedToNonGeoStringFieldWithMultiplePathComp
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionParams::initialize2dsphereParams(infoObj, &collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(obj, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << getCellID(0, 0) << ""
<< "gnirts"));
@@ -305,11 +306,11 @@ TEST(S2KeyGeneratorTest, CollationAppliedToStringsInArray) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionParams::initialize2dsphereParams(infoObj, &collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(obj, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << getCellID(0, 0) << ""
<< "gnirts"));
expectedKeys.insert(BSON("" << getCellID(0, 0) << ""
@@ -328,11 +329,11 @@ TEST(S2KeyGeneratorTest, CollationAppliedToStringsInAllArrays) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionParams::initialize2dsphereParams(infoObj, &collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(obj, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << getCellID(0, 0) << ""
<< "gnirts"
<< ""
@@ -362,11 +363,11 @@ TEST(S2KeyGeneratorTest, CollationDoesNotAffectNonStringFields) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionParams::initialize2dsphereParams(infoObj, &collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(obj, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << getCellID(0, 0) << "" << 5));
assertKeysetsEqual(expectedKeys, actualKeys);
@@ -382,11 +383,11 @@ TEST(S2KeyGeneratorTest, CollationAppliedToStringsInNestedObjects) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
ExpressionParams::initialize2dsphereParams(infoObj, &collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(obj, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << getCellID(0, 0) << "" << BSON("c"
<< "gnirts")));
@@ -403,11 +404,11 @@ TEST(S2KeyGeneratorTest, NoCollation) {
const CollatorInterface* collator = nullptr;
ExpressionParams::initialize2dsphereParams(infoObj, collator, &params);
- BSONObjSet actualKeys;
+ BSONObjSet actualKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths actualMultikeyPaths;
ExpressionKeysPrivate::getS2Keys(obj, keyPattern, params, &actualKeys, &actualMultikeyPaths);
- BSONObjSet expectedKeys;
+ BSONObjSet expectedKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
expectedKeys.insert(BSON("" << getCellID(0, 0) << ""
<< "string"));