Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Aggregation aggregation = newAggregation(
- match(Criteria.where("idOfUser").is(loggedInAccount.getId())),
- group("imgID"),
- new CustomAggregationOperation(
- new BasicDBObject("$lookup",
- new BasicDBObject("from","img")
- .append("localField","_id")
- .append("foreignField","_id")
- .append("as","uniqueImgs")
- )
- ),
- limit(pageable.getPageSize()),
- skip(pageable.getPageSize()*pageable.getPageNumber())
- );
- AggregationResults aggregationResults = mongo.aggregate(aggregation, "comment", String.class); //Using String at the moment just to see the output clearly.
- public class CustomAggregationOperation implements AggregationOperation {
- private DBObject operation;
- public CustomAggregationOperation (DBObject operation) {
- this.operation = operation;
- }
- @Override
- public DBObject toDBObject(AggregationOperationContext context) {
- return context.getMappedObject(operation);
- }
- }
- [{ "_id" : "570e2f5cb1b9125510a443f5" , "uniqueImgs" : [ ]}]
- LookupOperation lookupOperation = LookupOperation.newLookup()
- .from("img")
- .localField("_id")
- .foreignField("_id")
- .as("uniqueImgs");
- Aggregation agg = newAggregation(
- match(Criteria.where("idOfUser").is(loggedInAccount.getId())),
- group("imgID"),
- lookupOperation,
- limit(pageable.getPageSize()),
- skip(pageable.getPageSize()*pageable.getPageNumber())
- );
- AggregationResults aggregationResults = mongo.aggregate(agg, "comment", String.clas);
- db.country.aggregate([{ $lookup: { from: "state", localField: "countryId", foreignField: "countryId", as: "address"}}])
- My following code in java ,however, returns an empty list .
- LookupOperation lookUpOprn = LookupOperation.newLookup()
- .from("state")
- .localField("countryId")
- .foreignField("countryId")
- .as("address");
- List<BasicDBObject> list = mongoTemplate.aggregate(aggregation, "country", BasicDBObject.class).getMappedResults();
- Can you please help
Add Comment
Please, Sign In to add comment