My data model looks something like this:
{
"ListingId": 1,
"Status": "Current",
"Category": "Rental"
}
I have around 5 million documents, and would like to run aggregations on both the "status" and "category" fields, so i can produce an output like this:
{
"Statuses":
{
"Current": 100, // count of all documents with 'Status' = 'Current'
"Sold": 12 // count of all documents with 'Status' = 'Sold'
// etc
},
"Categories":
{
"Sale": 120,
"Rental": 12
// etc
}
}
Basically, i want to return data to power a 'faceted search' UI, so i need the count's of all facets, and I want to do it in one trip to MongoDB.
I've been reading up about Aggregations and Facets for a day or so now, and i'm still confused.
Questions:
Related questions (which i haven't been able to convert to my situation / code):
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.