Category "aggregation-framework"

MongoDB Group by field, count it with condition

I would like to count different hu for a shipment. So I write this query but how I can count different hu group by shipment ? my query : db.eventstranslated.agg

MongoDB - How to bring age group data

How to bring age group base data from a collection in MongoDB i.e how many people are 0-18, 19-24, 25-34, 35+ [ { "_id": ObjectId("608be7c608c7de2367c8963

Mongoose and MongoDB - Get all countries and users associated with country

So I have a list of posts data that looks like this: [ {user: 'Bob', country: 'USA'} {user: 'Kim', country: 'Mexico'} {user: 'Darren', country: 'Mexico'}

Query over a field which is deep inside MongoDB collection using array of possible options

I have a list of commentDocument collection in MongoDB where each has the following structure: { "commentName": "test comment", "outputs": { "ex

Access root document map in the $filter aggregation (MongoDb)

I apologize for the vague question description, but I have quite a complex question regarding filtration in MongoDB aggregations. Please, see my data schema to

Slow query using aggregation framework mongodb

I came up with this code to query a list of questions from db question .aggregate([ { $lookup: { from: "answers", localFie

Find in which polygon certain coordinate (latitude, longitude) lies with MongoDB?

Let's say 100 documents (so to say polygons) in a collection named Areas with this structure: { ...otherFields, commonName: "Butwal", area: { type: "

Is there a way to perform subquery on MongoDB using collection.aggregate() and PHP Driver?

I am migrating a MySQL table which has 50 million+ rows and 40 columns to a MongoDB database. This table data is shown on a html table and every column is searc

MongoDB - Group by inner element

I am explaining with a simple example see my MongoDB collection looks like this: [ { pid: erwer, qty: 3, LevelDetails: {

MongoDB query to find top store from list of orders

I'm pretty new to Mongo. I have two collections that look as follows. Order collection [ { id: 1, price: 249, store: 1, status: true

MongoDB - Loop through array of arrays

I have a document that contains an array of arrays in my MongoDB collection. { "platformId":"CMC_123", "carInfo":[ ["Toyota",20,"White"],

How to create nested array inside $group in MongoDB?

After some of the aggregation pipeline stages, my MongoDB Document has the following format: { "key": "A", "status": "To Do", "val": 4 }, {

lookup on all documents inside an array - MongoDB aggregation

I need to execute a lookup stage on all documents inside an array. The collection: { { "name": "test", "age": 2, "replies": [ {

MongoDB indexes are ignored inside the $facet pipeline

I have all combination of compound indexes for this collection. The aggregattion query i used is: db.products.aggregate( [ { $facet: { "categ

Delete result of mongodb $lookup aggregation

How do I delete all the chunks documents which are returned as a result of this aggregation? db.getCollection('chunks').aggregate([ { $lookup:

MongoDB optimize indexes for aggregation

I have an aggregate on a collection with about 1.6M of registers. That consult is a simple example of other more complex, but illustrate the poor optimization o

MongoDB: subtract months from date, with value from database

Is it possible in MongoDB to somehow subtract only months from a date, with a value from the same document. So for example i have to subtract date from field "v

How do I use Spring Mongo to group two fields and get a array of one fields based on the other?

Let me give a example here: Two entries in the collection Author: { "name" : "Joe" "Book" : "A" }, { "name" : "Joe" "Book" : "B" } Now, if I use the aggrega

MongoDB Duplicate Documents even after adding unique key

I have created a collection and added a unique key like this db.user_services.createIndex({"uid":1 , "sid": 1},{unique:true,dropDups: true}) The collection

Calculate the median in MongoDB aggregation framework

Is there a way to calculate the median using the MongoDB aggregation framework?