aggregation-framework Questions

1

Solved

MongoDB Aggregation - Find Documents within Specific Hour Range and Date I have a MongoDB collection with documents containing an orderDate field of type ISODate. I want to find the documents where...
Stereograph asked 6/8 at 14:21

2

Solved

Does anyone know how to add an array element to a mongodb array and set a "virtual" order to the size of the array, all in an atomic operation? So, something like: db.users.updateOne( { ...
Anatropous asked 4/8 at 7:19

2

I have a collection of messages which stores the following information code: a unique identification code of the message from: phone number the message was sent from to: phone number the message w...
Huai asked 21/9, 2017 at 8:37

2

Solved

I have documents of the form: { _id : ObjectId(.....), prop1 : "foo", links : [ 1, 2, 3, 4 ] } { _id : ObjectId(.....), prop1 : "bar", links : [ 5, 6, 7, 8 ] } I am using the aggregation ...
Scrim asked 11/12, 2013 at 11:19

7

Solved

I want to show products by ids (56e641d4864e5b780bb992c6 and 56e65504a323ee0812e511f2) and show price after subtracted by discount if available. I can count the final price using aggregate, but th...
Riobard asked 24/3, 2016 at 4:27

8

Solved

I have a query like this (simplified): db.collection.aggregate([ { $match: { main_id: ObjectId("58f0f67f50c6af16709fd2c7") } }, { $group: { _id: "$name", count: { $sum: 1...
Electric asked 21/4, 2017 at 8:43

2

Solved

I have a MongoDB collection called changes which contains the following data { "date" : ISODate("2014-06-09T00:00:00.000Z"), "field" : "ip", "from&qu...
Schermerhorn asked 10/6, 2014 at 13:57

3

Solved

I want to perform an aggregation query that does basic pagination: Find all orders that belongs to a certain company_id Sort the orders by order_number Count the total number of documents Skips t...
Hartz asked 17/1, 2018 at 16:21

3

Solved

I have a collection that looks like this: { "value" : "20", "type" : "square", "name" : "form1" } { "value" : "24", "type" : "circle", "name" : "form2" } { "value" : "12", "type" : "square", "nam...
Docker asked 8/11, 2018 at 15:5

4

Solved

REF: MongoDB Document from array with field value max Answers in Finding highest value from sub-arrays in documents and MongoDB find by max value in array of documents suggest to use sort + limit(...
Fromm asked 21/1, 2019 at 14:41

23

I want to convert ObjectID (Mongodb) to String in JavaScript. When I get a Object form MongoDB. it like as a object has: timestamp, second, inc, machine. I can't convert to string.
Transect asked 10/5, 2013 at 8:58

3

Solved

This should be a quick 2 minute find, but i'm searching for an hour and can't find any solution. How can i capitalize first letter of each word of the username field? { "_id" : ObjectId("5908...
Cross asked 3/5, 2017 at 8:36

2

I have a collection that looks like that { "_class" : "User", "_id" : "id1", "places" : [ { "_id" : "1", "address" : "test1", "location" : { "latitude" : 1, "longitude" : 1 } }, { "_i...
Boschbok asked 8/2, 2014 at 18:55

4

Solved

I'm running an aggregation on a collection of around 300k+ records which requires several unwinds and regroups. I'm hitting the following error; 'exception: Exceeded memory limit for $group, but d...
Affiance asked 27/5, 2014 at 16:5

18

Solved

I am interested in optimizing a "pagination" solution I'm working on with MongoDB. My problem is straight forward. I usually limit the number of documents returned using the limit() functionality. ...
Spessartite asked 15/2, 2014 at 20:33

3

Mongodb 3.2, installed on centos 6, with plenty of RAM and disk. I've a collection with 10K documents of the following structure: { "id":5752034, "score":7.6, "name":"ASUS X551 15.6-inch Laptop...
Khaki asked 1/6, 2016 at 21:35

3

Solved

I use aggregation framework for group by of multiple fields as { _id:{_id:"$_id",feature_type:"$feature_type",feature_name:"$feature_name"}, features: { $push: "$features" } } it give result lik...
Rositaroskes asked 12/7, 2018 at 6:51

3

Solved

With a collection of documents with fields field1, field2, field3 and so on, I need to find distinct values for field3 for each distinct value of field3, need to get the first document with each ...
Semiquaver asked 17/2, 2017 at 13:56

6

Solved

So as you all know, find() returns an array of results, with findOne() returning just a simply object. With Angular, this makes a huge difference. Instead of going {{myresult[0].name}}, I can simp...
Kennith asked 8/6, 2016 at 1:2

20

Solved

Suppose you have the following documents in my collection: { "_id":ObjectId("562e7c594c12942f08fe4192"), "shapes":[ { "shape":"square", "color":"blue" }, { "shape":"circle", "color"...
Freitas asked 21/10, 2010 at 7:31

3

I am using the $sample query for mongo aggregation. in the following manner: db.col.aggregate([ {$match: {topic: topic}}, {$sample: {'size': 10}} {$project: {_id: 1}} ]) My question is, is t...
Kroon asked 18/4, 2016 at 9:56

4

Solved

I've been looking for a while now and can't seem to sort an inner array and keep that in the doc that I'm currently working with. { "service": { "apps": { "updates": [ { "n" : 1 "date": ISOD...
Imposture asked 13/3, 2013 at 14:28

5

Field is added but then disappears. Here is the code from within the mongo shell: > db.users.aggregate([{$addFields:{totalAge:{$sum:"$age"}}}]) { "_id" : ObjectId("5acb81b53306361018814849"), "...
Uppermost asked 9/4, 2018 at 23:7

3

Solved

I am attempting to delete all the documents returned by an aggregation in Mongodb. The query I have is as follows: db.getCollection("Collection") .aggregate([ { $match: { status: { $in: ["inse...
Bolan asked 6/11, 2019 at 12:7

2

Solved

Mongodb provides lots of 'Date Aggregation Operators' such as $dayOfYear, $dayOf Month, and $millisecond. The $millisecond function just returns the milliseconds of the time stamp with a range of 0...
Directoire asked 10/3, 2014 at 18:30

© 2022 - 2024 — McMap. All rights reserved.