Questions tagged [aggregation-framework]

1 votes
1 replies
How to group by element in object of nested array
I have nested arrays and objects. I want to filter out each medicine separately. Such as document: { person: "X", treatment: [...
asked 4 months ago
1 votes
1 replies
I want every nth document from Database MongoDB
this are my collection of about 250k documents: { "_id" : ObjectId("5ccfbae47dd9094e30998954"), "date" : "05/02/2019" } { "_id"...
0 votes
0 replies
Cannot match after project
I am trying to match after project in a aggregate query. I have added the match query after the project query on the pipeline. Match on non loo...
0 votes
0 replies
Adding and counting fields through Aggregation Pipeline - Mongo
I have a set of data: Branch Status Product_Category Number_Of_Clients Amount 1 Ongoing Product1 20...
3 votes
1 replies
Count distinct MongoDb from array of values
I have an array of distinct items - search = alluk.distinct('Object of search') I am looking to do a count for each item. Currently I am doing...
0 votes
0 replies
Why reduce must return object with the same type as value emitted by map function?
In MongoDB documentation, in MapReduce section one can read The reduce function must return an object whose type must be identical to the typ...
2 votes
2 replies
MongoDB Remove or Limit fields conditional aggregation
I am having some issue writing a find/aggregate mongo query where my requirement is to get all the documents but having condition like: Suppose...
3 votes
1 replies
MGO Pipe with $lookup query won't attach matching documents from “joined” collection
My Models type ( //Category implements item category in database Category struct { ID bson.ObjectId `bson:"_id,omitempt...
asked 4 months ago
1 votes
1 replies
Mongodb query, flatten objects with array
A document: { objectId: 35, properties: [ { pset: 'A1', property: 'Fire', value: '60' }, { pset...
asked 4 months ago
1 votes
1 replies
Field must be an accumulator object error when trying to group by object as key
I'm trying to type-safe group documents by multiple properties from a collection. I figured out that the problem is not the grouping by multiple...
1 votes
1 replies
MongoDB - Apply similar lookup on multiple columns in main table
I'm a newbie to MongoDB, I'm trying to aggregate complete details of students in referencing with other collections. students collection structu...
1 votes
1 replies
$lookup with pipe line not populating the data?
I have two schema as follow const CoconutImportSchema = new Schema({ userId: { type: Schema.Types.ObjectId, ref: 'User',...
2 votes
1 replies
How to unwind array inside object in MongoDB?
I have about MongoDB in unwind operator. So, I have document like this. { "name": "abc", "report": { "_2019": { "Ma...
1 votes
1 replies
How to create view to read from two collections in mongoDB?
Started with mongoDB syntax and use in project. I am looking for a solution where I can combine more than two collections with couple of conditi...
asked 4 months ago
0 votes
0 replies
Mongodb aggregation on multiple fields. How to alias _id field to map to proper object
Below is the mongo db query and respective Java code using morphia. Where I want to alias _id field when I am aggregating with multiple field. Th...
0 votes
2 replies
Mongodb find duplicates where second column matches
I want to find duplicate documents in my mongodb database , and i have also achieved a portion of it , lets say my document is something like thi...
1 votes
2 replies
How to perform lookup in aggregation when foreignField is in array?
I have two collections: // users { _id: "5cc7c8773861275845167f7a", name: "John", accounts: [ { "_id": "5cc7c8...
0 votes
0 replies
How to use a “contain” (string) under $cond
I am trying to $addFields at the aggregation framework. I am using $cond and I wish (for an existing variable) that all strings that contain "opt...
asked 4 months ago
0 votes
1 replies
How to fetch all fields of parent document?
I have tried to fetch all fields of parent document using $group but it send only specific fields.Another Question. How to fetch all fields of pa...
1 votes
2 replies
MongoDB: Check for array for object and if exists return true, otherwise false
I'm trying to query an array within a collection and project the value "true" if the object exists within the array. If the object doesn't exist...
1 votes
1 replies
mongodb use $lte with $indexOfArray
for a collection with the model { stack: [{mean: 3.5}] } how can I make this query for the index of the stack array with a mean of less th...
2 votes
2 replies
How to use $lookup and $in mongodb aggregate
Colleges { "_id" : ObjectId("5cd42b5c65b41027845938ae"), "clgID" : "100", "name" : "Vivekananda" }, { "_id" : ObjectId("5cd...
1 votes
1 replies
match aggregation for array not working as expected Mongodb
I want to find all record which exists between input arguments. If I pass as both from and to arguments as same then It should find an exact matc...
asked 4 months ago
2 votes
1 replies
mongoose populate sort _ Mongoose Node.js
I have two schemas that represent my post and category documents. I'm trying to sort my posts with category.order property. order property is a n...
1 votes
1 replies
exception: geoNear command failed: errmsg: more than one 2d index, not sure which to run geoNear on
I'm trying to retrieve documents from a collection by distance. I've tried to use the $geoNear aggregation, but I either run into errors (using n...