-
Notifications
You must be signed in to change notification settings - Fork 156
Description
Any solution for the above issue?
I have a similar issue here
My query on Mongo Shell is like -
db.getCollection('cm').aggregate([
{ "$match": { "ID": "2006"} },
{
"$lookup": {
"from": "cm",
"localField": "Parent",
"foreignField": "_id",
"as": "bList"
}
},
{"$unwind":"$bList"},
{
"$lookup": {
"from": "cm",
"localField": "bList.Parent",
"foreignField": "_id",
"as": "bList1"
}
},
{"$unwind":"$bList1"},
{
$project: {
"_id": 0,
"DivisionId": "$bList.Parent",
"GroupID": "$bList._id",
"GroupName": "$bList.Name",
"DivisionName":"$bList1.Name"
}
}
])
JSON document 1: -
{ "_id" : "ProductGroup2006", "Parent" : "Group6", "Ancestors" : [ "Division2", "Group6" ], "ID" : "2006" }
JSON document 2:
{ "_id" : "Division2", "Parent" : "", "Ancestors" : [], "Name" : "Sujay Godbole", "Type" : "Division" }
JSON Document 3
{ "_id" : "Group6", "Parent" : "Division2", "ID" : "6", "Ancestors" : [ "Division2" ], "Name" : "Chirag Mehta" }
After adding all these documents to the Collection in JUNIT class, call the below:
`List aggregation = new ArrayList();
aggregation.add(Aggregates.match(Filters.eq("ID", "2006")));
aggregation.add(Aggregates.lookup("cm", "Parent", "_id", "siblingList"));
aggregation.add(Aggregates.unwind("$siblingList"));
aggregation.add(Aggregates.lookup("cm", "siblingList.Parent", "_id", "ancestorList"));
aggregation.add(Aggregates.unwind("$ancestorList"));
aggregation.add(Aggregates.project(
new Document("_id", 0).append("DivisionId", "$siblingList.Parent").append("GroupId", "$siblingList._id")
.append("GroupName", "$siblingList.Name").append("DivisionName", "$ancestorList.Name")));`
Finally -
AggregateIterable<Document> iterable = mongoCollection.aggregate(aggregate);
And this action results in EMPTY objects
ISSUE: My main() works and returns results; but the same in Fongo - collection.aggregate(), return EMPTY results.
Any help/resolution appreciated