Top "Aggregation-framework" questions

The MongoDB Aggregation Framework provides a means to reshape and aggregate data in MongoDB 2.2+.

MongoDB Aggregation: Counting distinct fields

I am trying to write an aggregation to identify accounts that use multiple payment sources. Typical data would be. { account:"…

mongodb aggregation-framework
Find all duplicate documents in a MongoDB collection by a key field

Suppose I have a collection with some set of documents. something like this. { "_id" : ObjectId("4f127fa55e7242718200002d"), "id":1, "…

mongodb mapreduce duplicates aggregation-framework
MongoDB Aggregation - match if value in array

I have a collection that I'm performing an aggregation on and I've basically gotten it down to {array:[1,2,3], value: 1}, {array:[1,2,3], …

mongodb aggregation-framework
$match in $lookup result

I have next mongo code: db.users.aggregate([ { $match: { $and: [ { UserName: { $eq: 'administrator' } }, { 'Company.CompanyName': { $eq: 'test' } } ] } }, { $lookup: { from: "companies", …

mongodb mongodb-query aggregation-framework
Mongo $group with $project

I am trying to get keyword count along with parentId, categioryId and llcId. My db is { "_id" : ObjectId("5673f5b1…

mongodb aggregation-framework
Is there an elseif thing in MongoDB to $cond while aggregating

So I need a custom field calculated in MongoDB as follows if( field1 =="A") ->customfield=10 else if(field1 =="…

mongodb mongodb-query aggregation-framework
Get n-th element of an array in MongoDB

As part of my document in MongoDB I'm storing an array of objects. How can I query it for only …

mongodb mongodb-query aggregation-framework
Conditional $sum in MongoDB

My collection in mongodb is similar to the following table in SQL: Sentiments(Company,Sentiment) Now, I need to execute …

mongodb mongodb-query aggregation-framework
$skip and $limit in aggregation framework

When I read the document I found the following notes: When a $sort immediately precedes a $limit in the pipeline, …

mongodb aggregation-framework
How do I rename fields when performing search/projection in MongoDB?

Is it possible to rename the name of fields returned in a find query? I would like to use something …

mongodb mongodb-query aggregation-framework