Questions tagged [aggregation-framework]

1

votes
1

answer
233

Views

TypeError: callback.apply is not a function after allowDiskUse

I have a collection having 1Million documents... I have passed the option for allowDiskUse and now it is throwing error TypeError: callback.apply is not a function I have searched for this but could get the solution... Please help const pictures = await Picture.aggregate([ { $sort: { createdAt: -1 }...
Anthony Winzlet
1

votes
3

answer
49

Views

How to make lookup between two collections when an item in an array exists in the other collection?

In Lookup with a pipeline, I would like to get the linked records from an array in the parent document. // Orders [{ '_id' : ObjectId('5b5b91a25c68de2538620689'), 'Name' : 'Test', 'Products' : [ ObjectId('5b5b919a5c68de2538620688'), ObjectId('5b5b925a5c68de2538621a15') ] }] // Products [ { '_id'...
Homam
1

votes
1

answer
30

Views

Sum all named fields in aggregation

I am trying to calculate the sum of all the values below. I have tried googling the question in different ways but cannot find an answer. The data looks like this. I don't care about the keys, I am just looking for a total of the values for monday 'monday' : { 'a' : 5, 'b' : 2, 'c' : 1, 'd' : 2, 'e...
MC101
1

votes
1

answer
37

Views

MongoDB - how unpack object?

document: {'_id':'5cb0dfe234a8a30c9c0af127', 'sensors': [{'value0':0.153, 'value1':-0.306, 'value2':9.807}], 'timestamp':1555095522489,'__v':0} I want to get 4 field (timestamp and value 0..2) without any array / object. unwind work only against array but not objects. What should I do? desired outpu...
Dmitry Sokolov
1

votes
2

answer
42

Views

Group by time interval between window of time

I have the following document structure: { '_id':'5c59c35d8610f702d00e6f70', 'ipAddress':'50.116.14.48', 'startTime':'2018-02-06T12:01:59.000Z', 'endTime':'2018-02-06T12:31:00.000Z', } I would like to be able to group occurrences within a 15 min window of time. For example; Given the structure of...
Sixthpoint
4

votes
0

answer
18

Views

parent children hierarchy mongodb aggregation pipeline

My Documents in collection: /* 1 createdAt:4/22/2019, 4:53:32 PM*/ { '_id' : ObjectId('5cbdab3c9bd57541040342a1'), 'created_on' : '2017-03-07T21:07:04.778Z', 'feature' : 'Source', 'feature_option' : 'write', 'icon' : 'fa fa-plus', 'is_deleted' : false, 'level' : 2, 'modified_on' : '2017-03-07T21:07:...
Abdul Moiz
1

votes
1

answer
43

Views

Retrieve documents where birthday is today

I've the following collection called 'members': { '_id' : ObjectId('5a477681bbe5f506e68d29b7'), 'name' : 'mario', 'surname' : 'rossi', 'email' : '[email protected]', 'birth' : ISODate('1998-12-29T23:00:00Z'), 'fc' : null, 'expires' : ISODate('2018-12-29T23:00:00.183Z') }, { '_id' : ObjectId('5a47...
Raffaele
1

votes
1

answer
225

Views

Mongodb: db undefined on connect

I am trying to access mongodb through native driver. When i use connect method in my remote method. I am getting connected successfully but i am getting 'undefined' as db object Purpose : Getting all fields name from collection. Activation.getUserFields = function (id, callbackFn) { Activation.app.d...
Ankur Akvaliya
1

votes
2

answer
76

Views

MongoDB Aggregation by Name and Different Time Interval

I've been looking for a solution for several days, and I can not get a result. Please, help me! I have a data in MongoDB: { name: 'apple', date: 2018-01-04T10:00:00.000Z, price: 100 } { name: 'apple', date: 2018-01-04T10:01:00.000Z, price: 101 } { name: 'apple', date: 2018-01-04T10:02:00.000Z, price...
COS
1

votes
0

answer
101

Views

MongoDB - aggregating data between two collections

My application is a reservation system that uses full calendar API. The calendar has a seller and a customer that are routed to view the same calendar and see the same events. The seller creates resources on the calendar and the customer can see the same resources and book them on his end. My goal:...
asus
1

votes
1

answer
124

Views

spring data mongodb embeded query

{ '_id' : '7959305563', '_class' : 'com.loylty.messagingEngine.entities.message.GroupIdDeliveryStatusReport', 'DATA_LIST' : [ { '_id' : '7959305562-1', 'mobile' : '9566337867', 'status' : 'DELIVRD', 'senttime' : '2018-01-09 14:19:42', 'dlrtime' : '2018-01-09 14:57:06', 'custom' : '9566337867' }, {...
Muddassir Rahman
1

votes
1

answer
226

Views

Pymongo aggregation - passing python list for aggregation

Here is my attempt at performing the aggregation (day-wise) based on timestamp if all the elements are hardcoded inside the query. pipe = [ { '$match': { 'cid': ObjectId('57fe39972b8dbc1387b20913') } }, { '$project': { 'animal_dog': '$animal.dog', 'animal_dog_tail': '$animal.dog.tail', 'animal_cat...
elevenmac
1

votes
2

answer
66

Views

MongoDB. Get prices for different time period for each product in one query

I have some problem with correct query to MongoDB. I have many documents about prices for each product, for different time. The updates come from 3rd party service, almost every second for each product in live time. Sometimes i has 2–3 updates about prices in one second, or for some products 1 upd...
COS
1

votes
2

answer
306

Views

MongoDB Facet results formatting

I have a query construction with $facet, that return results in this format: {price_now: [ { _id: 'apple', price_now: 1.02 }, { _id: 'melon', price_now: 3.18 }, { _id: 'cherry', price_now: 2.57 }], price_15m: [ { _id: 'apple', price_15m: 1.08 }, { _id: 'melon', price_15m: 3.12 }, { _id: 'cherry', pr...
COS
1

votes
1

answer
53

Views

Mongodb arithmetic expression of elements inside an array

{ '_id' : ObjectId('5a4d0712368ff072a56a66e8'), 'a' : { 'nodes' : [ { 'b' : 1 }, { 'c' : { 'nodes' : [ { 'd' : 2 }, { 'e' : 2 } ] } } ] }, 'r' : 1 } { '_id' : ObjectId('5a4d0712368ff072a56a66e9'), 'a' : { 'nodes' : [ { 'b' : 4 }, { 'c' : { 'nodes' : [ { 'e' : 9 } ] } } ] }, 'r' : 2 } Above are the s...
daemon24
1

votes
1

answer
53

Views

How to use aggregate and sum while writing to MongoDB?

I'm complete beginner with mongodb, javascript and coding overall, this part of my project is giving me hard times. I have read manuals in mongodb websites, tried look from here practical example for my case, but with bad results. Wanted action is to read values to variables from webpage and write...
Jiikoo
1

votes
2

answer
121

Views

MongoDB sort is slow for non-index dynamic field

Following is my MongoDB query to show the organization listing along with the user count per organization. As per my data model, the 'users' collection has an array userOrgMap which maintains the organizations ( by orgId) to which the user belongs to. The 'organization' collection doesn't store the...
karmaker
1

votes
1

answer
217

Views

GraphQL error returning result of mongoose aggregate command

This question is related to the answer posted here I need to return an aggregation result from a GraphQL query. Here is the query code: const companiesWithNoUsers = { type: new GraphQLList(CompanyType), resolve(root, args, context) { return Company.aggregate([ { $lookup: { from: 'users', localField:...
Mendes
1

votes
0

answer
585

Views

MongoDB $lookup: Multiple Join Conditions on field in array

I have an issue with joining documents in mongo based on conditions on a nested field in an array. Basically, I want to filter the documents of the foreign collection. I was following the example on the official MongoDB documentation for Multiple Join Conditions with $lookup and extended it to fit m...
peterschrott
1

votes
2

answer
55

Views

mongodb counting document pairs

Let's imagine I have MongoDB collection with elements of such type: { '_id' : 'id1', 'from' : 'Tom', 'to' : 'Bill' }, { '_id' : 'id2', 'from' : 'Jack', 'to' : 'Tom' }, { '_id' : 'id3', 'from' : 'Jack', 'to' : 'Tom' }, { '_id' : 'id4', 'user' : 'Tom', 'to' : 'Jack' }, { '_id' : 'id4',...
1

votes
1

answer
83

Views

How to merge multiple fields in a collection?

Example entry: { '_id' : '[email protected]', ' pass' : 123654, 'field2' : 235689, 'field3' : 'cccp123654', 'field4' : 'lhfrjy' } Desired result: { '_id' : '[email protected]', ' pass' : 123654, 235689, 'cccp123654', 'lhfrjy' } I want to have two final fields (_id and pass). I have attempted the following:...
user9249456
1

votes
0

answer
60

Views

How to count value of matching with the field value in mongoDB

I have a document in which perform 2 task. I am new in mongoDB ,These tasks are very small and trying to explain. To calculate number of users which have values of start hour, start Min, and start Sec these values should be less than or equal to start_min, start_hour which is defined in dObject.(W...
Rahul Saini
1

votes
1

answer
37

Views

How to use Aggregation along with group by and sum

How to get the sum of purchased deal's price (current year data) group by week, day, year using purchased_at field My collection data: { '_id': ObjectId('5a66d619042e9f3a070d6864'), 'name': 'Deal1', 'price': '2000', 'status': true, 'purchased_at': ISODate('2018-01-23T06:28:41.0Z') } { '_id': ObjectI...
amit
1

votes
0

answer
125

Views

Count occurrence of each value inside an array for each document with mongodb

I have a problem with MongoDB that I am not able to solve... I have a list of documents and each document contains an array of String called 'types'. Here an example: { '_id' : 19841, 'types' : [ 'A', 'A', 'B', 'C' ], 'other_fields' : 1, /* 2 */ { '_id' : 11212, 'types' : [ 'A', 'B' ], 'othe...
sabfon
1

votes
2

answer
111

Views

aggregate group distinct on array of objects after querying

I have array of products where a product looks like this: { 'invNumber':445, 'attributes': [ { 'id': 'GR1', 'value': '4', 'description': 'Re/Rek' }, { 'id': 'WEBAKKUNDE', 'value': '2', 'description': 'NO' }, { 'id': 'WEBAKKUNDK', 'value': '1', 'description': 'YES' }, { 'id': 'WEBAKMONTO', 'value': '...
Bujar Deari
1

votes
1

answer
803

Views

Mongodb - aggregation and batchSize - cursor not found after 1 minute

I have an unusual mongodb cursor-timeout issue - I get a cursor not found error even though the timeout of 10 minutes has not been reached. My env: ubuntu 14.04 LTS PHP 7.1.13 libmongoc bundled version 1.8.2 MongoDB extension version 1.3.3 mongodb/mongodb 1.2.0 Here is some code. In short, I loop ov...
mils
1

votes
1

answer
346

Views

multiple group by query in mongodb aggregate

This is the structure of my document { '_id' : '8113593870', '_class' : 'com.loylty.messagingEngine.entities.message.GroupIdDeliveryStatusReport', 'DATA_LIST' : [ { '_id' : '8113593870-1', 'mobile' : '7874671667', 'status' : 'DELIVRD', 'senttime' : '2018-01-30 13:29:40', 'dlrtime' : '2018-01-30 13...
Muddassir Rahman
1

votes
1

answer
590

Views

MongoDB aggregate - using $filter with $in condition for projection

db.getCollection('regions').aggregate([ { $match: { 'status': 1 }, { $project: { names: { $filter: { input: '$names', as: 'name', cond: {$or: [ { $eq: ['$$name.lang', 'de'] }, { $eq: ['$$name.lang', 'en'] }, { $eq: ['$$name.lang', 'es'] }, ]} }} }} ]) Is it possible to replace the $or condition with...
Stephan
1

votes
0

answer
587

Views

PropertyReferenceException: No property _id found for type Entity

I am using spring boot and mongodb for my project. I faced a problem with a property _id in my repository class. Before executing this query which is generated by my repositoryImpl class, I executed generated query in mongodb and it works fine. If you change _id to id in java code, the PropertyRefe...
vertex
1

votes
2

answer
212

Views

Get count of unique ObjectId from array MongoDB

I'm new to working with MongoDb and do not know a lot of things. I need to write an aggregation request. Here is the JSON document structure. { '_id' : ObjectId('5a72f7a75ef7d430e8c462d2'), 'crawler_id' : ObjectId('5a71cbb746e0fb0007adc6c2'), 'skill' : 'stack', 'created_date' : ISODate('2018-02-...
layjel
1

votes
0

answer
150

Views

How to remove a field from an array using aggregate on MongoDB?

{Crs:{[ {Cr: { '_id' : ObjectId('5a75baada0f20bd4e612d480'), 'Number' : 400, 'Page' : 24, 'DC' : 'NE', }}, {Cr: { '_id' : ObjectId('5a75baada0f20bd4e612d489'), 'Number' : 300, 'Page' : 14, 'DC' : '100', }}, ]}} I have this data that i model using aggregate and I would like to know how can i remove '...
pp fernandes
1

votes
0

answer
192

Views

MongoDB aggregate query how to split the array element

In my mongodb, i have few collections, i want to create a new collection by comparing the collection 1 and collection 2 using pymongo. Collection 1 : Object id timestamp Prof_Name SUBJECT abc67478898k ISODate('2018-01-03T09:26:37.541Z') ABDC 'sub1, sub2, sub3...
Rachel
1

votes
1

answer
32

Views

MongoDB $lookup Value Back into Array

I have a document with multiple items, that need to lookup further information from another collection to fill out the data. Main Document: { _id: ObjectID('5a30ff41af58f911946b122e'), SalesItems: [ { SalesItemID: 1139, Quantity: 2, Amount: 3.00 }, { SalesItemID: 2549, Quantity: 1, Amount: 5.40 } ]...
DanielWoodward
1

votes
1

answer
308

Views

mongodb aggregate not match query

I have a collection name users details below [{ 'userId': '00UPQAARGT7', 'userPreferences': [{ 'pId': '59SDS64675A00096D48CB', 'pData': [{ 'name': 'FORMAT', 'value': 'CSV' }, { 'name': 'LAN', 'value': 'E' } ] }, { 'pId': '59SDS64675A00096D59DB', 'pData': [{ 'name': 'FORMAT', 'value': 'DOC' }, { 'na...
Johne Doe
1

votes
2

answer
156

Views

How to sum the array size across the entire collection?

i hava a mongodb json data. { '_id' : ObjectId('1111111111111111'), 'teamId' : '111', 'scoreId' : '50dcefb52d764ca3913985a80a4162ef', 'utterances' : [ { 'text' : 'test1', 'parsedText' : 'test1' }, { 'text' : 'test2', 'parsedText' : 'test2' } ] }, { '_id' : ObjectId('22222222222222'), 'teamId' : '1...
james
1

votes
1

answer
44

Views

Filtering out the unique values between 2 mongodb arrays using mongodb 3.4

I have 2 arrays: 'array1': ['057a7', '05790', '0575d', '0579f', '0576b', '05784', '05775'] 'array2': ['0579f', '057a7', '05790', '05784', '0575d', '0576a', '0576b', '05775'] I have tried $setDifference, $setUnion and $setIntersection and these only output the elements that match. I would like to ou...
Pablo.K
1

votes
1

answer
83

Views

Is it possible to do a lookup on a view in mongodb?

I am trying to build a new mongodb view using an aggregation with a $lookup stage that joins to a mongodb view I built. Here is a sample of the resulting output from my view named myPreferencesView: { '_id' : ObjectId('58c3127b30abaf0d1ae38235'), 'name' : 'Preference 1', 'pointValue' : NumberInt(...
joshblair
1

votes
1

answer
234

Views

Pentaho BI - MongoDB input Aggregation error due to recent MongoDB upgrade to 3.6

Due to recent Mogodb upgrade to 3.6, pentaho kettle mongoinput step aggregation not be able to fetch data from the Mongodb. The error message: com.mongodb.MongoCommandException: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' on server l...
Elias Gezahegn
1

votes
0

answer
41

Views

How to merge records in mongodb with aggregate

I have a collection named 'timestamp' and each time_in, time_out, break_start, and break_end has separate record. What i want is to merge records with the same date. From this: Unmerged Data: { '_id' : ObjectId('5a94f3e461613268eaecc59c'), 'staff_id' : NumberInt(173), 'time_in' : ISODate('2018-02...
noyruto88
1

votes
0

answer
693

Views

Mongodb aggregation with days between two dates [duplicate]

This question already has an answer here: MongoDB group by date intervals 2 answers Mongo Aggregation : $group and $project array to object for counts 1 answer mongo: new Date() in aggregate $project 2 answers I have two dates, I need to get all days (Mar 1, 2018 | Mar 2, 2018 ...) between those...
JMA

View additional questions