aggregation-framework

mongodb $group compare one collection to other collection

こ雲淡風輕ζ 提交于 2020-04-30 06:24:50
问题 I got stuck in one point. See this playground, it should follow this logic: if history's collection is empty, return data if history's date collection is greater then main's collection base on specified user_id , return nothing if specified user_id doesn't match with history's collection date then it should return all data that is in main collection. So everything looks fine in playground the only problem when i am putting 5e4e74eb380054797d9db623 id it should not return me data because its

mongoDB: $dateToString format to show time by 15min interval

社会主义新天地 提交于 2020-04-27 07:17:52
问题 I have a example here, https://mongoplayground.net/p/fqxBy6NAZXL As you will see final result has "dateHour" and "minuteBucket" fields. I am dividing time by 15.0 minutes so "minuteBucket" value will always be one of 0, 1, 2, 3 "dateHour" is not showing minutes right now. Expected : I need to remove "minuteBucket" field but still divide time by 15 minutes for this aggregation and show "dateHour" with HH:MM where it always round up by 15 minutes. example it should look like in this format

MongoDB: Calculate dwell time between every status value change

∥☆過路亽.° 提交于 2020-04-24 07:54:22
问题 I want to find out the dwell time between every presenceStatus change. Example collection - /* 1 */ { "_id" : ObjectId("5e4889a7c7959f6a13039902"), "presenceStatus" : 0, "createdAt" : ISODate("2020-02-16T00:14:35.121Z"), "updatedAt" : ISODate("2020-02-16T00:14:35.121Z"), "__v" : 0 } /* 2 */ { "_id" : ObjectId("5e4889a7c7959f6a1303990c"), "presenceStatus" : 1, "createdAt" : ISODate("2020-02-16T00:15:35.121Z"), "updatedAt" : ISODate("2020-02-16T00:15:35.121Z"), "__v" : 0 } /* 3 */ { "_id" :

MongoDB: Calculate dwell time between every status value change

限于喜欢 提交于 2020-04-24 07:54:13
问题 I want to find out the dwell time between every presenceStatus change. Example collection - /* 1 */ { "_id" : ObjectId("5e4889a7c7959f6a13039902"), "presenceStatus" : 0, "createdAt" : ISODate("2020-02-16T00:14:35.121Z"), "updatedAt" : ISODate("2020-02-16T00:14:35.121Z"), "__v" : 0 } /* 2 */ { "_id" : ObjectId("5e4889a7c7959f6a1303990c"), "presenceStatus" : 1, "createdAt" : ISODate("2020-02-16T00:15:35.121Z"), "updatedAt" : ISODate("2020-02-16T00:15:35.121Z"), "__v" : 0 } /* 3 */ { "_id" :

group collection data by multiple fields mongodb

核能气质少年 提交于 2020-04-21 06:10:07
问题 Collection Structure Order = new Schema index: { type: Number, unique: true } number: Date status: { type: String, enum: ['success', 'failure'] } created_at: { type: Date, default: Date.now } updated_at: { type: Date, default: Date.now } I need help with a query that returns me an array of objects having data as success count and failure count grouped by date. Ex- orders = { 28-10-2016:{ success_count: 10, failure_count: 10 }, 29-10-2016: { success_count: 10, failure_count: 10 } } 回答1: With

group collection data by multiple fields mongodb

情到浓时终转凉″ 提交于 2020-04-21 06:07:52
问题 Collection Structure Order = new Schema index: { type: Number, unique: true } number: Date status: { type: String, enum: ['success', 'failure'] } created_at: { type: Date, default: Date.now } updated_at: { type: Date, default: Date.now } I need help with a query that returns me an array of objects having data as success count and failure count grouped by date. Ex- orders = { 28-10-2016:{ success_count: 10, failure_count: 10 }, 29-10-2016: { success_count: 10, failure_count: 10 } } 回答1: With

update aggregate results in mongodb?

…衆ロ難τιáo~ 提交于 2020-04-18 08:51:29
问题 Considering the following schema for workorders collection. {"Activity #": "1111111", "Customer": "Last, First", "Tenure": "0 Year 2 Months", "Account #": "0000000", "lines": [{ "Line#": "line#", "Product": "product", "Status": "status", "price": "price" }, { "Line#": "line#", "Product": "product", "Status": "status", "price": "price" }]} I can get all my closed line items with the following query. db.workorders.aggregate({$match:{"Status":"Closed"}},{$unwind:"$lines"},{$match:{"lines.Status"

How to lookup a field in an array of subdocuments in mongoose?

与世无争的帅哥 提交于 2020-04-18 05:47:25
问题 I have an array of review objects like this : "reviews": { "author": "5e9167c5303a530023bcae42", "rate": 5, "spoiler": false, "content": "This is a comment This is a comment This is a comment.", "createdAt": "2020-04-12T16:08:34.966Z", "updatedAt": "2020-04-12T16:08:34.966Z" }, What I want to achieve is to lookup the author field and get the user data, but the problem is that the lookup I am trying to use only returns this to me: Code : .lookup({ from: 'users', localField: 'reviews.author',

mongodb + group by with multiple collections

99封情书 提交于 2020-04-17 22:05:50
问题 I have 3 to 4 collections users payments branches grades In users table we have multiple types of users like student, parents like this. In payments table user payments details have payments details with partical amount or full amount. In branches, table have branch details. I am trying find the reports based on branches and grades wise. total numbers of users in that branch total numbers of paid users in that branch based on paidStatus column. total sum amount recieved in that branch based

mongodb + group by with multiple collections

一世执手 提交于 2020-04-17 22:05:17
问题 I have 3 to 4 collections users payments branches grades In users table we have multiple types of users like student, parents like this. In payments table user payments details have payments details with partical amount or full amount. In branches, table have branch details. I am trying find the reports based on branches and grades wise. total numbers of users in that branch total numbers of paid users in that branch based on paidStatus column. total sum amount recieved in that branch based