Questions tagged [mongodb-aggregation]

MongoDB is a NoSQL database with the intent of storing billions of records. It offers the aggregation framework as a tool to manipulate and query records. This tag is intended to be used with question specific to this aggregation framework, since aggregation is too general.

147 questions
2
votes
0 answers

Combining results from different aggregate queries

If you have 3 different MongoDb Aggregate queries based on 3 different collections, each calculating a score for that Dept in a company, how does one combine / $project the results into 1 combined executive report by use of query, without storing…
Albert
  • 81
  • 4
2
votes
1 answer

Group by day/month/week basis on the date range

This is in reference to this question. This is my data set: [ { "rating": 4, "ceatedAt": ISODate("2016-08-08T15:32:41.262+0000") }, { "rating": 3, "createdAt": ISODate("2016-08-08T15:32:41.262+0000") }, { "rating": 3, …
nirvair
  • 4,001
  • 10
  • 51
  • 85
2
votes
1 answer

MongoDB join two collections using aggregation $lookup or populate in Node.js

Here are two collections' schema var activitySchema = new Schema({ activity_id: {type: String, index: {unique: true}, required: true}, begin_date : String, ... }) var registrationSchema = new Schema({ activity_id: {type:…
2
votes
1 answer

Mongo Aggregation $filter on ISO date value

I have the following document { "_id": "57b4c5f0291ebb13110b888e", "first": "John", "last": "Smith", "email": "John.Smith@gmail.com", "fulfillments": [ { "_id": "57b683e531a5a21679b78e6d", "created_by_name": "John Smith", …
2
votes
1 answer

how to combine projection and pagination in mongodb?

I have a document structure such as this: { "name":"test", "family":"test", score:[ { "point":3, "des":"blah" }, { "point":4, "des":"blahblah" }, { "point":5, …
Navid_pdp11
  • 3,487
  • 3
  • 37
  • 65
2
votes
1 answer

C# MongoDb Project with DateTime.date

Given: I've a mongodb collection with some data. One field is a DateTime field . Now I want to aggregate the data for each day. for this I created this aggregation var result = collection .Aggregate() .Project(i =>…
Boas Enkler
  • 12,264
  • 16
  • 69
  • 143
2
votes
1 answer

Count ocurrence of two fields

I have this kind of documents in a MongoDb collection: [ { "_id": { "id": 892, "answer": "C", "level": "regular" }, "total": 4 }, { "_id": { "id": 891, "answer": "Regular", "level":…
viniciusbo
  • 53
  • 6
2
votes
1 answer

Boolean Expression with String Comparison in Mongodb?

$cond in mongodb is defined like this: $cond: { if: { $gte: [ "$qty", 250 ] }, then: 30, else: 20 } But, can we do that for a string ? I want to compare string value inside a document with regex, so something like this can work: $cond: { if: {…
DennyHiu
  • 4,861
  • 8
  • 48
  • 80
1
vote
1 answer

mongoDB aggregate query returning results in reverse order

My aggregation pipeline on mongoDB is…
Sourabh Jain
  • 55
  • 1
  • 4
1
vote
3 answers

Mongodb geonear and aggregate very slow

My current mongo version is 2.4.9 and collection have around 2.8millions rows. My query take super long to finish when using $geonear in the query. Example of my collection "loc" : { "type" : "Point", "coordinates" : [ 100.46589473,…
Eric
  • 1,547
  • 2
  • 18
  • 34
1
vote
0 answers

Count mismatch in $substr aggregate function mongodb

i have some data where ISO date is getting stored as string and i am running $substr to get the count Match with substring in mongodb aggregation but count mismatch is coming day by day. couldnot able to figure out why. database is in mlab.com which…
Priyanka D L
  • 171
  • 1
  • 8
1
vote
2 answers

How to get the top five fastest ground speeds using mongodb

So I have this data imported from excel and I want to be able find the top five fastest speeds. I tried using the aggregate function but what was returned was 0. db.planes.aggregate({ $group : { _id : "$msg_dummy", fastest :…
1
vote
1 answer

How to Check current user's vote before votes are grouped and sumed in same aggregate function

var PostSchema = new mongoose.Schema({ item: { type: mongoose.Schema.ObjectId, ref: 'item', required: true }, user: { type: mongoose.Schema.ObjectId, ref: 'User', required: true }, vote: { type:…
NoobSter
  • 1,150
  • 1
  • 16
  • 39
1
vote
2 answers

Max query in mongodb with where clause

I want create a MAX query in MongoDB with where clause. I try this db.Collection.aggregate({$group : {_id : "$P_ID", massi : {$max : "$b_val"}}},{P_ID:'XYZ',experiment:'abc'}); My WHERE clause is {P_ID:'XYZ',experiment:'abc'} I don't why but this…
1
vote
2 answers

Mongodb group documents and limit each group

Considering those documents: { "Field1":"Test_1", "Speaker":1, "Listener":2, "ListenTime": ISODate("2016-10-15T14:17:49.336Z") }, { "Field1":"Test_2", "Speaker":1, "Listener":2, "ListenTime":…