aggregation-framework

Performing case-statement in mongodb aggregation framework

北城余情 提交于 2019-12-17 07:29:16
问题 I'm evaluating how well the MongoDB aggregation framework suits our needs as we are currently running on top of SQL Server. I'm having a hard time performing a specific query: Say I have the following pseudo records (modeled as columns in a sql table and as a full document in a mongodb collection) { name: 'A', timespent: 100, }, { name: 'B', timespent: 200, }, { name: 'C', timespent: 300, }, { name: 'D', timespent: 400, }, { name: 'E', timespent: 500, } I want to group the timespent field in

Multiple Counts with single query in mongodb

﹥>﹥吖頭↗ 提交于 2019-12-17 06:54:35
问题 I am new to Mongo Db and would appreciate some help with this query. I have been sifting through posts here for the past couple of days tearing my hair to see if I could find anything related to my query but with no luck. I have a collection with documents similar in structure to below : _id: xyz Movieid: 123 MovieName: Titanic ReleaseDate: 2000-01-01 _id: uvw Movieid: 456 MovieName: Titanic II ReleaseDate: 2018-01-01 _id: pqr Movieid: 789 MovieName: Titanic III ReleaseDate: I would like to

Multiple Counts with single query in mongodb

江枫思渺然 提交于 2019-12-17 06:54:07
问题 I am new to Mongo Db and would appreciate some help with this query. I have been sifting through posts here for the past couple of days tearing my hair to see if I could find anything related to my query but with no luck. I have a collection with documents similar in structure to below : _id: xyz Movieid: 123 MovieName: Titanic ReleaseDate: 2000-01-01 _id: uvw Movieid: 456 MovieName: Titanic II ReleaseDate: 2018-01-01 _id: pqr Movieid: 789 MovieName: Titanic III ReleaseDate: I would like to

Remove Duplicates from MongoDB

﹥>﹥吖頭↗ 提交于 2019-12-17 06:14:40
问题 hi I have a ~5 million documents in mongodb (replication) each document 43 fields. how to remove duplicate document. I tryed db.testkdd.ensureIndex({ duration : 1 , protocol_type : 1 , service : 1 , flag : 1 , src_bytes : 1 , dst_bytes : 1 , land : 1 , wrong_fragment : 1 , urgent : 1 , hot : 1 , num_failed_logins : 1 , logged_in : 1 , num_compromised : 1 , root_shell : 1 , su_attempted : 1 , num_root : 1 , num_file_creations : 1 , num_shells : 1 , num_access_files : 1 , num_outbound_cmds : 1

exclude fields in $lookup aggregation

假如想象 提交于 2019-12-17 05:15:13
问题 I am querying between 3 collections I want to exclude _id everywhere in output My output is: { "_id" : ObjectId("5b6aed5f9bcdb5d4ae64aef5"), "userID" : "1", "skills" : [ { "_id" : ObjectId("5b766b5f1365a4940bb6050f"), "skillID" : "javaid", "skillname" : "जावा", "languageID" : "hindiid" }, { "_id" : ObjectId("5b766b8c1365a4940bb60535"), "skillID" : "pythonid", "skillname" : "पायथन", "languageID" : "hindiid" } ], "gender" : { "_id" : ObjectId("5b7687cd2a2329043e2383d5"), "genderID" : "femaleid"

What's the $unwind operator in MongoDB?

拈花ヽ惹草 提交于 2019-12-17 04:47:54
问题 This is my first day with MongoDB so please go easy with me :) I can't understand the $unwind operator, maybe because English is not my native language. db.article.aggregate( { $project : { author : 1 , title : 1 , tags : 1 }}, { $unwind : "$tags" } ); The project operator is something I can understand, I suppose (it's like SELECT , isn't it?). But then, $unwind (citing) returns one document for every member of the unwound array within every source document . Is this like a JOIN ? If yes, how

Average Aggregation Queries in Meteor

≡放荡痞女 提交于 2019-12-17 03:38:14
问题 Ok, still in my toy app, I want to find out the average mileage on a group of car owners' odometers. This is pretty easy on the client but doesn't scale. Right? But on the server, I don't exactly see how to accomplish it. Questions: How do you implement something on the server then use it on the client? How do you use the $avg aggregation function of mongo to leverage its optimized aggregation function? Or alternatively to (2) how do you do a map/reduce on the server and make it available to

Matching ObjectId to String for $graphLookup

旧时模样 提交于 2019-12-17 02:51:34
问题 I'm trying to run a $graphLookup like demonstrated in print bellow: The objective is to, given a specific record (commented $match there), retrieve it's full "path" throught immediateAncestors property. As you can see, it's not happening. I introduced $convert here to deal with _id from collection as string , believing it could be possible to "match" with _id from immediateAncestors records list (which is a string ). So, I did run another test with different data (no ObjectId s involved): db

Matching ObjectId to String for $graphLookup

久未见 提交于 2019-12-17 02:51:19
问题 I'm trying to run a $graphLookup like demonstrated in print bellow: The objective is to, given a specific record (commented $match there), retrieve it's full "path" throught immediateAncestors property. As you can see, it's not happening. I introduced $convert here to deal with _id from collection as string , believing it could be possible to "match" with _id from immediateAncestors records list (which is a string ). So, I did run another test with different data (no ObjectId s involved): db

Check if every element in array matches condition

£可爱£侵袭症+ 提交于 2019-12-17 02:38:19
问题 I have a collection of documents: date: Date users: [ { user: 1, group: 1 } { user: 5, group: 2 } ] date: Date users: [ { user: 1, group: 1 } { user: 3, group: 2 } ] I would like to query against this collection to find all documents where every user id in my array of users is in another array, [1, 5, 7]. In this example, only the first document matches. The best solution I've been able to find is to do: $where: function() { var ids = [1, 5, 7]; return this.users.every(function(u) { return