Questions tagged [nosql-aggregation]

Questions related to Aggregation functions in NoSQL databases.

Questions related to Aggregation functions such as Count() or Sum() in NoSQL databases.

313 questions
2
votes
1 answer

Avoid duplicate documents and Lookup with same 'as' key

I'm trying to make an aggregate work with mongoose but I'm having several problem, Document from Users Model { "_id": { "$oid": "630273bbe0f3f82d85b149bd" }, "password": "$2b$12$2f04ijl0fDVHUgBF3rZi.eKfNYkzHZShHNPKfiDEu2NXEXhb.2O", …
2
votes
1 answer

Aggregation to filter reference in MongoDB

I'm trying to make an aggregate work with mongoose but I'm having a problem, I'm getting this result: [ { _id: new ObjectId("630bb658370cc689973c5bb4"), isRead: true, user: new ObjectId("630273bbe0f3f82d85b149bd"), globalRef:…
2
votes
1 answer

Get filtered elements from array of object in mongodb document based on flag in elements

I have a one collection called User. Every user consists data like below document. I want to get an user with history data but history array should contains only active records in the array. { "_id" : ObjectId("62f1df89fd621s2c419e5d47"), …
2
votes
0 answers

mongodb querying next N documents

In Mongodb, is it possible to query the next N documents? i.e collection.find({ 'temperature': 1.0 }).sort("datetime", 1).next({ [ 'temperature': 1.1, 'temperature': 1.2 ] }, 2) query would return results only after document where temperature 1.0…
povici
  • 29
  • 4
2
votes
1 answer

Query maximum N records of each group base on a condition in MongoDB?

I have a question regarding querying data in MongoDB. Here is my sample data: { "_id": 1, "category": "fruit", "userId": 1, "name": "Banana" }, { "_id": 2, "category": "fruit", "userId": 2, "name": "Apple" }, { …
Tunz Daoz
  • 23
  • 3
2
votes
0 answers

Mongo aggregation query works in MongoDB but not working in AWS DocumentDB

I wrote a mongo query which worked fine in MongoDB but it is not working in AWS DocumentDB Here is the query: const collection = db.collection('items'); const query = [ { $addFields: { files: { …
2
votes
1 answer

Mongodb: $expr comparing two elements of same array in same document

I have some documents with an array v containing exactly 2 objects with two numbers a and b as properties. I want to filter in an aggregation the documents where the two objects in the array have the same b value. for instance, having this…
EuberDeveloper
  • 874
  • 1
  • 14
  • 38
2
votes
2 answers

MongoDB sum of all fields with integer values

inside the aggregation framework, it's possibile in some way, for each document like this below: { "Title": "Number orders", "2021-03-16": 3, "2021-03-15": 6, "2021-03-19": 1, "2021-03-14": 19 } Obtain a new document like this? { …
2
votes
1 answer

Unwind, but keep original array in each result row

{ name: 'John Smith', appointments: [ {date: 'date1', type: 'type one'}, {date: 'date2', type: 'type two'} ] }, { name: 'Michael Jackson', appointments: [ {date: 'date3', type: 'type three'}, ] } As…
E F
  • 474
  • 3
  • 15
2
votes
2 answers

How to aggregate array value objects by key in MongoDB

Given the following collection { "_id": 1, "items": [ { "k": "A", "v": 1 }, { "k": "B", "v": 2 } ] } { "_id": 2, "items": [ { "k": "A", "v": 3 }, { "k": "B", "v": 4 } ] } How can I sum all the items having the same key k, preserving the original…
2
votes
1 answer

How do I enforce ordering (ORDER BY) in a custom Presto Aggregation Function

I am writing a custom Presto Aggregation Function that produces the correct result if (and only if) the values are ordered in ascending order by the value that I am aggregating on. i.e. The following will work: SELECT key, MY_AGG_FUNC(value ORDER BY…
Marsellus Wallace
  • 17,991
  • 25
  • 90
  • 154
2
votes
2 answers

How to create an array containing arrays on MongoDB

I'm trying to make a query to mongodb. I want to get an array containing [location, status] of every document. This is how my collection looks like { "_id": 1, "status": "OPEN", "location": "Costa Rica", "type": "virtual store" }, { "_id":…
Newbie Dev
  • 69
  • 6
2
votes
0 answers

Calculate data day by day and create monthly data in Mongo

I have a collection in mongo, and its data is; [ { "_id": "AAAAA", "date": "17-01-2020", "query": { "user_overview":{ "total": 5, "view": 15}, "device":[ { "name": "Samsung",…
ozcanyarimdunya
  • 2,324
  • 1
  • 18
  • 21
2
votes
1 answer

How to compare documents in the same collection?

I am a novice when it comes to mongo as I have traditionally only worked with Oracle database. I have a mongo database that's storing bitbucket data in columns like so: _id | _class | collectorItemId| firstEverCommit | scmUrl | scmBranch |…
2
votes
2 answers

How to count number of documents that have a maximum unique value considering every subfield within a given field?

Problem Given this structure: { "_id": ObjectId("56n606c39q49b80adfe6d17b") "data": { "field1": [ { "subfield1.1": [ { "val1.1.1": a }, …
feran
  • 293
  • 3
  • 9
1 2
3
20 21