DATAMONGO-2096 - Fix target field name for GraphLookup aggregation operation.
We now make sure to use the target field name instead of the alias when processing GraphLookupOperation. Original pull request: #613.
This commit is contained in:
committed by
Mark Paluch
parent
ec5268a862
commit
c738148b40
@@ -104,8 +104,8 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
|
||||
graphLookup.put("startWith", mappedStartWith.size() == 1 ? mappedStartWith.iterator().next() : mappedStartWith);
|
||||
|
||||
graphLookup.put("connectFromField", connectFrom.getName());
|
||||
graphLookup.put("connectToField", connectTo.getName());
|
||||
graphLookup.put("connectFromField", connectFrom.getTarget());
|
||||
graphLookup.put("connectToField", connectTo.getTarget());
|
||||
graphLookup.put("as", as.getName());
|
||||
|
||||
if (maxDepth != null) {
|
||||
@@ -113,7 +113,7 @@ public class GraphLookupOperation implements InheritsFieldsAggregationOperation
|
||||
}
|
||||
|
||||
if (depthField != null) {
|
||||
graphLookup.put("depthField", depthField.getName());
|
||||
graphLookup.put("depthField", depthField.getTarget());
|
||||
}
|
||||
|
||||
if (restrictSearchWithMatch != null) {
|
||||
|
||||
@@ -133,4 +133,40 @@ public class GraphLookupOperationUnitTests {
|
||||
assertThat(dbObject, is(JSON.parse("{ $graphLookup : { from: \"employees\", startWith: { $literal: \"hello\"}, "
|
||||
+ "connectFromField: \"reportsTo\", connectToField: \"name\", as: \"reportingHierarchy\" } }")));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2096
|
||||
public void connectFromShouldUseTargetFieldInsteadOfAlias() {
|
||||
|
||||
AggregationOperation graphLookupOperation = Aggregation.graphLookup("user").startWith("contacts.userId")
|
||||
.connectFrom("contacts.userId").connectTo("_id").depthField("numConnections").as("connections");
|
||||
|
||||
DBObject document = graphLookupOperation.toDBObject(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
assertThat(document, is(JSON.parse(
|
||||
"{ \"$graphLookup\" : { \"from\" : \"user\", \"startWith\" : \"$contacts.userId\", \"connectFromField\" : \"contacts.userId\", \"connectToField\" : \"_id\", \"as\" : \"connections\", \"depthField\" : \"numConnections\" } }")));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2096
|
||||
public void connectToShouldUseTargetFieldInsteadOfAlias() {
|
||||
|
||||
AggregationOperation graphLookupOperation = Aggregation.graphLookup("user").startWith("contacts.userId")
|
||||
.connectFrom("userId").connectTo("connectto.field").depthField("numConnections").as("connections");
|
||||
|
||||
DBObject document = graphLookupOperation.toDBObject(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
assertThat(document, is(JSON.parse(
|
||||
"{ \"$graphLookup\" : { \"from\" : \"user\", \"startWith\" : \"$contacts.userId\", \"connectFromField\" : \"userId\", \"connectToField\" : \"connectto.field\", \"as\" : \"connections\", \"depthField\" : \"numConnections\" } }")));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2096
|
||||
public void depthFieldShouldUseTargetFieldInsteadOfAlias() {
|
||||
|
||||
AggregationOperation graphLookupOperation = Aggregation.graphLookup("user").startWith("contacts.userId")
|
||||
.connectFrom("contacts.userId").connectTo("_id").depthField("foo.bar").as("connections");
|
||||
|
||||
DBObject document = graphLookupOperation.toDBObject(Aggregation.DEFAULT_CONTEXT);
|
||||
|
||||
assertThat(document, is(JSON.parse(
|
||||
"{ \"$graphLookup\" : { \"from\" : \"user\", \"startWith\" : \"$contacts.userId\", \"connectFromField\" : \"contacts.userId\", \"connectToField\" : \"_id\", \"as\" : \"connections\", \"depthField\" : \"foo.bar\" } }")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user