diff options
-rw-r--r-- | jstests/aggregation/bugs/server19095.js | 25 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_lookup.cpp | 8 |
2 files changed, 32 insertions, 1 deletions
diff --git a/jstests/aggregation/bugs/server19095.js b/jstests/aggregation/bugs/server19095.js index fdd0454ac47..d36dba74141 100644 --- a/jstests/aggregation/bugs/server19095.js +++ b/jstests/aggregation/bugs/server19095.js @@ -378,6 +378,31 @@ load("jstests/aggregation/extras/utils.js"); testPipeline(pipeline, expectedResults, coll); // + // Query-like local fields (SERVER-21287) + // + + // This must only do an equality match rather than treating the value as a regex. + coll.drop(); + assert.writeOK(coll.insert({_id: 0, a: /a regex/})); + + from.drop(); + assert.writeOK(from.insert({_id: 0, b: /a regex/})); + assert.writeOK(from.insert({_id: 1, b: "string that matches /a regex/"})); + + pipeline = [ + {$lookup: { + localField: "a", + foreignField: "b", + from: "from", + as: "b", + }}, + ]; + expectedResults = [ + {_id: 0, a: /a regex/, b: [{_id: 0, b: /a regex/}]} + ]; + testPipeline(pipeline, expectedResults, coll); + + // // Error cases. // diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp index 07ba3e97b7d..83708c8756c 100644 --- a/src/mongo/db/pipeline/document_source_lookup.cpp +++ b/src/mongo/db/pipeline/document_source_lookup.cpp @@ -116,7 +116,13 @@ BSONObj DocumentSourceLookUp::queryForInput(const Document& input) const { if (localFieldVal.missing()) { localFieldVal = Value(BSONNULL); } - return BSON(_foreignFieldFieldName << localFieldVal); + + // { _foreignFieldFiedlName : { "$eq" : localFieldValue } } + BSONObjBuilder query; + BSONObjBuilder subObj(query.subobjStart(_foreignFieldFieldName)); + subObj << "$eq" << localFieldVal; + subObj.doneFast(); + return query.obj(); } boost::optional<Document> DocumentSourceLookUp::unwindResult() { |