java - Nested projection with spring aggregation -
i'm trying create projection on mongo collection using spring data mongo aggregation libraries.
assume have collection:
{ "_id": "33", "name": "foo", "payments": { "years": [{ "year": 2017, "quarters": [{ "quarter": 3, "transactions": [{ "amount": 800, "type": "varia" "dayofmonth": 10 }] }] }] }
i use mongo aggregation query:
db.customers.aggregate( { $match: { "_id": {$in: ["33", "80"] } }}, { $project: { "payments":{"years":{"quarters":{"transactions":{"amount":1,"type":1}}}} } }, { $unwind: "$payments.years" }, { $unwind: "$payments.years.quarters" }, { $unwind: "$payments.years.quarters.transactions" }, { $match: { "payments.years.quarters.transactions.amount": {$ne: "0.00" }} }, { $group: { "_id": "$_id", "payments": {"$push": "$payments.years.quarters.transactions"} }} )
but trying implement in java application now. use spring-data-mongo.
i tried way i'm receiving 0 results.
matchoperation matchallklantenstage = aggregation.match(new criteria("_id").in(ids)); projectionoperation projectstage = project() .and("payments.years.quarters.transactions") .nested(bind("type","payments.years.quarters.transactions.type") .and("amount", "payments.years.quarters.transactions.amount") .and("dayofmonth", "payments.years.quarters.transactions.dayofmonth")); aggregation aggregation = newaggregation( matchallklantenstage, projectstage, unwind("payments.years.quarters.transactions"), match(new criteria("payments.years.quarters.transactions.amount").ne("0.00")), group().push("payments.years.quarters.transactions").as("payments") );
can me this?
kind regards,
kaj
Comments
Post a Comment