mongodb-query

MongoDb: find deeply nested object with $lookup

纵然是瞬间 提交于 2020-05-04 10:54:10
问题 I have collection like this: collection name is - account. and it has sub-documents like account > buildings > gateways > devices. { "_id" : ObjectId("5e1fe45cd05bfb0cc549297d"), "apiCallCount" : 0, "email" : "info@data.com", "password" : "dummy", "userName" : "AAAAA", "companyName" : "The AAAAAA", "apiKey" : "5e1fe45cd05bfb0cc549297c", "solutionType" : "VVVVVV", "parentCompany" : "", "buildings" : [ { "_id" : ObjectId("5e1fe5e3d05bfb0cc5494146"), "buildingName" : "xxxxxx", "address" : "xxx",

MongoDb: find deeply nested object with $lookup

99封情书 提交于 2020-05-04 10:54:00
问题 I have collection like this: collection name is - account. and it has sub-documents like account > buildings > gateways > devices. { "_id" : ObjectId("5e1fe45cd05bfb0cc549297d"), "apiCallCount" : 0, "email" : "info@data.com", "password" : "dummy", "userName" : "AAAAA", "companyName" : "The AAAAAA", "apiKey" : "5e1fe45cd05bfb0cc549297c", "solutionType" : "VVVVVV", "parentCompany" : "", "buildings" : [ { "_id" : ObjectId("5e1fe5e3d05bfb0cc5494146"), "buildingName" : "xxxxxx", "address" : "xxx",

I have a mongodb query and I want to find the exact match word “Approved”

こ雲淡風輕ζ 提交于 2020-04-30 06:41:05
问题 I have a mongodb query and I want to find the exact match word "Approved" in Array named "Sales.Action". But the other "Sales.Action" array has the value "Approve" which is also returning. I have tried $elemMatch but still it is not working. Here is my json: { "Sales" : [ { "Action" : [ "Approved" ], "Log" : [ "Created on: 04/20/2020 42:04:04" ] }, { "Action" : [ "Approve", "Decline", "Edit", "Remarks" ], "Log" : [ "Created on: 04/20/2020 42:04:04" ] }, { "Action" : [ "Approve", "Decline",

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

Does MongoDB have a way to update a document without dropping existing elements not contained in the update data

谁说胖子不能爱 提交于 2020-04-18 07:15:23
问题 I have been using MongoDB with both .NET core and Node.js. This question is specific to a node project I am working on, but I think the client language is irrelevant to my questions. I have a document that has elements like name and address current ("add_current") below: { "_id" : ObjectId("5d858718c1d9f856881dc9ce"), ... "name": "John Doe", "add_current" : { "add1" : "456 Old Ave.", "city" : "Stafford", "state" : "VA", "zip" : "23234" }, ... } Sometimes I am just updating some parts of the

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',