diff options
Diffstat (limited to 'src/mongo/db/pipeline/document_source_graph_lookup.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/document_source_graph_lookup.cpp | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/mongo/db/pipeline/document_source_graph_lookup.cpp b/src/mongo/db/pipeline/document_source_graph_lookup.cpp index 044875f737f..62a35123173 100644 --- a/src/mongo/db/pipeline/document_source_graph_lookup.cpp +++ b/src/mongo/db/pipeline/document_source_graph_lookup.cpp @@ -544,46 +544,56 @@ void DocumentSourceGraphLookUp::checkMemoryUsage() { _cache.evictDownTo(_maxMemoryUsageBytes - _frontierUsageBytes - _visitedUsageBytes); } -void DocumentSourceGraphLookUp::serializeToArray( - std::vector<Value>& array, boost::optional<ExplainOptions::Verbosity> explain) const { +void DocumentSourceGraphLookUp::serializeToArray(std::vector<Value>& array, + const SerializationOptions& opts) const { auto fromValue = (pExpCtx->ns.db() == _from.db()) - ? Value(_from.coll()) - : Value(Document{{"db", _from.db()}, {"coll", _from.coll()}}); + ? Value(opts.serializeIdentifier(_from.coll())) + : Value(Document{{"db", opts.serializeIdentifier(_from.db())}, + {"coll", opts.serializeIdentifier(_from.coll())}}); // Serialize default options. - MutableDocument spec(DOC("from" << fromValue << "as" << _as.fullPath() << "connectToField" - << _connectToField.fullPath() << "connectFromField" - << _connectFromField.fullPath() << "startWith" - << _startWith->serialize(false))); + MutableDocument spec(DOC("from" << fromValue << "as" << opts.serializeFieldPath(_as) + << "connectToField" << opts.serializeFieldPath(_connectToField) + << "connectFromField" + << opts.serializeFieldPath(_connectFromField) << "startWith" + << _startWith->serialize(opts))); // depthField is optional; serialize it if it was specified. if (_depthField) { - spec["depthField"] = Value(_depthField->fullPath()); + spec["depthField"] = Value(opts.serializeFieldPath(*_depthField)); } if (_maxDepth) { - spec["maxDepth"] = Value(*_maxDepth); + spec["maxDepth"] = Value(opts.serializeLiteral(*_maxDepth)); } if (_additionalFilter) { - spec["restrictSearchWithMatch"] = Value(*_additionalFilter); + if (opts.transformIdentifiers || + opts.literalPolicy != LiteralSerializationPolicy::kUnchanged) { + auto matchExpr = + uassertStatusOK(MatchExpressionParser::parse(*_additionalFilter, pExpCtx)); + spec["restrictSearchWithMatch"] = Value(matchExpr->serialize(opts)); + } else { + spec["restrictSearchWithMatch"] = Value(*_additionalFilter); + } } // If we are explaining, include an absorbed $unwind inside the $graphLookup specification. - if (_unwind && explain) { + if (_unwind && opts.verbosity) { const boost::optional<FieldPath> indexPath = (*_unwind)->indexPath(); spec["unwinding"] = Value(DOC("preserveNullAndEmptyArrays" - << (*_unwind)->preserveNullAndEmptyArrays() << "includeArrayIndex" - << (indexPath ? Value((*indexPath).fullPath()) : Value()))); + << opts.serializeLiteral((*_unwind)->preserveNullAndEmptyArrays()) + << "includeArrayIndex" + << (indexPath ? Value(opts.serializeFieldPath(*indexPath)) : Value()))); } array.push_back(Value(DOC(getSourceName() << spec.freeze()))); // If we are not explaining, the output of this method must be parseable, so serialize our // $unwind into a separate stage. - if (_unwind && !explain) { - (*_unwind)->serializeToArray(array); + if (_unwind && !opts.verbosity) { + (*_unwind)->serializeToArray(array, opts); } } |
