aggregation-framework

How do I count multiple keys in the same MongoDB aggregation $group query?

Deadly 提交于 2019-12-21 04:21:21
问题 I have a query: db.test.aggregate( {$group : { _id : '$key', frequency: { $sum : 1 } } } ) This will get the frequency of every enumeration of key in the test set. Basically, I have gotten the distribution of key. Now imagine I want to get the distributions of key1, key2, and key3 (so three different distributions). Obviously, I could run this query 3 times with each separate key, but it seems like we would be able to optimize the query by allowing it to count all 3 keys at the same time. I

How do I count multiple keys in the same MongoDB aggregation $group query?

不想你离开。 提交于 2019-12-21 04:21:12
问题 I have a query: db.test.aggregate( {$group : { _id : '$key', frequency: { $sum : 1 } } } ) This will get the frequency of every enumeration of key in the test set. Basically, I have gotten the distribution of key. Now imagine I want to get the distributions of key1, key2, and key3 (so three different distributions). Obviously, I could run this query 3 times with each separate key, but it seems like we would be able to optimize the query by allowing it to count all 3 keys at the same time. I

Aggregation pipeline and indexes

心已入冬 提交于 2019-12-21 04:14:39
问题 From http://docs.mongodb.org/manual/core/indexes/#multikey-indexes, it is possible to create an index on an array field using a multikey index. http://docs.mongodb.org/manual/applications/aggregation/#pipeline-operators-and-indexes lists some ways of how an index can be used in aggregation framework. However, there may be times that I may need to perform an $unwind on an array field to perform a $group . My question is, are multikey indexes (or any index using such array field) can still be

pymongo: remove duplicates (map reduce?)

醉酒当歌 提交于 2019-12-21 04:05:06
问题 I do have a Database with several collections (overall ~15mil documents) and documents look like this (simplified): {'Text': 'blabla', 'ID': 101} {'Text': 'Whuppppyyy', 'ID': 102} {'Text': 'Abrakadabraaa', 'ID': 103} {'Text': 'olalalaal', 'ID': 104} {'Text': 'test1234545', 'ID': 104} {'Text': 'whapwhapwhap', 'ID': 104} They all have an unique _id field as well, but I want to delete duplicates accodring to another field (the external ID field). First, I tried a very manual approach with lists

If Mongo $lookup is a left outer join, then how come it excludes non-matching documents?

自闭症网瘾萝莉.ら 提交于 2019-12-21 04:01:29
问题 The title says it all. How come if a document does not result in any matching outer document according to its matching field, then how come it's not included in the pipeline's result set? I'm testing out the new aggregators in Mongo 3.2 and I've gone so far as to perform a nested array lookup by first unwinding, and then grouping the documents back up. All I have left is to have the results include all local documents that didn't meet the $lookup criteria, which is what I thought was the

How to calculate difference between values of different documents using mongo aggregation?

戏子无情 提交于 2019-12-21 02:47:34
问题 Hi my mongo structure as below { "timemilliSec":1414590255, "data":[ { "x":23, "y":34, "name":"X" }, { "x":32, "y":50, "name":"Y" } ] }, { "timemilliSec":1414590245, "data":[ { "x":20, "y":13, "name":"X" }, { "x":20, "y":30, "name":"Y" } ] } Now I want to calculate difference of first document and second document and second to third in this way so calculation as below diffX = ((data.x-data.x)/(data.y-data.y)) in our case ((23-20)/(34-13)) diffY = ((data.x-data.x)/(data.y-data.y)) in our case

Mongodb aggregate, group and count instances

喜夏-厌秋 提交于 2019-12-21 02:27:07
问题 I have a document which looks like this: { "_id" : ObjectId("527a6b7c24a8874c078b9d10"), "day" : 6, "hour" : 15, "hourlyLocations" : [ { "countryName" : "Spain", "countryCode" : "ES", "cityName" : "Madrid", "latitude" : 40, "longitude" : -4 }, { "countryName" : "United Kingdom", "countryCode" : "GB", "cityName" : "Soest", "latitude" : 51.5, "longitude" : -0.13 } ], "minute" : 18, "month" : 11, "year" : 2013 } "hourlyLocations" is a series of embedded documents (just two shown here for brevity

MongoDB Aggregation V/S simple query performance?

帅比萌擦擦* 提交于 2019-12-20 20:39:20
问题 I am reasking this question as i thought this question should be on seperate thread from this one in-mongodb-know-index-of-array-element-matched-with-in-operator. I am using mongoDB and actually i was writing all of my queries using simple queries which are find, update etc. (No Aggregations). Now i read on many SO posts see this one for example mongodb-aggregation-match-vs-find-speed. Now i thought about why increasing computation time on server because as if i will compute more then my

MongoDB Aggregation V/S simple query performance?

泄露秘密 提交于 2019-12-20 20:38:35
问题 I am reasking this question as i thought this question should be on seperate thread from this one in-mongodb-know-index-of-array-element-matched-with-in-operator. I am using mongoDB and actually i was writing all of my queries using simple queries which are find, update etc. (No Aggregations). Now i read on many SO posts see this one for example mongodb-aggregation-match-vs-find-speed. Now i thought about why increasing computation time on server because as if i will compute more then my

MongoDB Aggregate $unwind $match using date - what did I miss?

十年热恋 提交于 2019-12-20 14:16:13
问题 I'm new in MongoDB and I'm trying to work with aggregations. I partially do what I'm looking for but I have a strange behavior with dates. MongoDB info Version : 2.2.0 Operating System : Windows 7 Objective Get all comments created after '2012-11-22' Let's get an example : Data db.blogs.save([ { title : "X this is my second title", author : "max", posted : new Date(), pageViews : 10, tags : [ "good", "nice" ], comments : [ { "_id" : ObjectId("50ac9fdb53a900bcb4be46d9"), author : "john", text