[Solved] How to get mongoDB aggregated month wise data using java [closed]

Use the aggregation framework with following aggregation pipeline (Mongo shell implementation): db.ledger.aggregate([ { “$unwind”: “$Accounts” }, { “$project”: { “Total_Credits” : “$Accounts.Total_Credits”, “Total_Debits” : “$Accounts.Total_Debits”, “month_year” : { “$substr”: [ “$Accounts.Date”, 3, -1 ] } } }, { “$group”: { “_id”: “$month_year”, “Total_Credits”: { “$sum”: “$Total_Credits” }, “Total_Debits”: { “$sum”: “$Total_Debits” } } } ]) … Read more

[Solved] MongoDB query condition including SUM

The $redact operator of the aggregation framework is your best option: db.collection.aggregate([ { “$redact”: { “$cond”: { “if”: { “$lt”: [ { “$add”: [ “$b”, “$c” ] }, 5 ] }, “then”: “$$KEEP”, “else”: “$$PRUNE” } }}, { “$project”: { “_id”: 0, “a”: 1 } } ]) The logical condition is made via $lt on … Read more