My schema goes something like this:
Registration: {
totalDue: Number,
amountPaid: Number,
charges: [
{
amount: Number,
paymentMethod: String,
status: String
}
]
}
I am building a reporting tool, so that users can query for charges by a given amount. For example, I want to show all successful charges with amounts greater than 30.
My current query is:
db.registrations.aggregate(
{$match: {'charges.status':'succeeded', 'charges.amount': {$gt: 30}}},
{$unwind:'$charges'},
{$match: {'charges.status':'succeeded', 'charges.amount': {$gt: 30}}},
{$project:{'charges':1}}
)
I'm getting the correct results, which is a list of charges, but I'm also new to mongodb so I'm unsure if there is a much better way of doing this. It seems like there would be a more efficient way then using $match twice with the same criteria, once to get all registrations with correct charges, and then again to filter the actual charges.
There may be many thousands of registrations, and each having anywhere from 0 to a few hundred charges.
By the way, when I run the query on robomongo, it only shows me 50 results, and no additional pages for me to scroll through, any idea why? I'm not using $limit.