I have this $lookup
operation and I have implemented it with Spring.
My problem is, that when I am running it in a shell it's working fine but with Spring it's not working. The interesting part is, that when I am adding a $match
into Spring (where I have implemented it), it's working.
But I don't need $match
I just need simple $lookup
without $match.
Please help me.
Thanks in Advance.
Mongo-Query :
db.twitterconnection.aggregate([
{ "$lookup": {
"from": "twitteruser",
"localField": "connection_id",
"foreignField": "user_id",
"as": "followers"
}}
]);
Spring Implementation:
public List <TwitterResult> lookupOperation(){
LookupOperation lookupOperation = LookupOperation.newLookup()
.from("twitteruser")
.localField("connection_id")
.foreignField("user_id")
.as("followers");
//Aggregation aggregation = Aggregation.newAggregation(Aggregation.match(Criteria.where("user_id").is("1")) , lookupOperation);//If I use this then it's working fine.
Aggregation aggregation = Aggregation.newAggregation(lookupOperation);
List<TwitterResult> results = (List<TwitterResult>) mongoTemplate.aggregate(aggregation, "twitterconnection", TwitterResult.class).getMappedResults();
System.out.println("Obj Size " +results.size());
System.out.println(" Results : "+results.toString());
return results;
}