Closed
Description
Wai Leong opened DATAMONGO-2096 and commented
Problems:
Connect from nested field "contacts.userId" with Aggregation.graphLookup.connectFrom
// with Aggregation.graphLookup connect from nested field "contacts.userId"
AggregationOperation graphLookupOperation =
Aggregation.graphLookup("user")
.startWith("contacts.userId")
.connectFrom("contacts.userId")
.connectTo("_id")
.depthField("numConnections")
.maxDepth(MAX_DEPTH_LEVEL)
.as("connections");
Command is generated with incorrect field name: ( "connectFromField" : "userId" )
[{ "$graphLookup" : { "from" : "user", "startWith" : "$contacts.userId", "connectFromField" : "userId", "connectToField" : "_id", "as" : "connections", "maxDepth" : 5, "depthField" : "numConnections" } }]
Alternative Solution:
Use Document to prepare graphlookup
//
AggregationOperation graphLookupOperation = aggregationOperationContext -> {
Document graphLookup = new Document(
"from", "user").append(
"startWith", "$contacts.userId").append(
"connectFromField", "contacts.userId").append(
"connectToField", "_id").append(
"depthField", "numConnections").append(
"maxDepth", MAX_DEPTH_LEVEL).append(
"as", "connections");
return new Document("$graphLookup", graphLookup);
};
This will generate correct command ("connectFromField" : "contacts.userId")
[{ "$graphLookup" : { "from" : "user", "startWith" : "$contacts.userId", "connectFromField" : "contacts.userId", "connectToField" : "_id", "depthField" : "numConnections", "maxDepth" : 5, "as" : "connections" } }]
Affects: 2.0.10 (Kay SR10), 2.1 GA (Lovelace)
Referenced from: pull request #613
Backported to: 2.1.1 (Lovelace SR1), 2.0.11 (Kay SR11), 1.10.16 (Ingalls SR16)