aggregation-framework

MongoDb: Convert date string to specific format in mongodb 3.6

青春壹個敷衍的年華 提交于 2020-05-09 07:17:08
问题 I need to parse date value to specific format without using format field in dateFromString operator. Mongo Playground Current situation : in Mongodb 4.0 if I format dateString using below it code it give me mentioned output. parsedDate: { $dateFromString: { dateString: "$dateS", format: format: "%Y-%m-%dT%H" } } Output: "parsedDate": ISODate("2020-01-16T08:00:00Z") I cannot use format field in 3.6 since its not supported. How do I convert my date to format: "%Y-%m-%dT%H" in 3.6? 回答1: If I get

Group by in mongoDB with property construction

老子叫甜甜 提交于 2020-05-09 06:26:27
问题 I have a collection named Accounts like below data /* 1 */ { "_id" : ObjectId("5e93fea52f804ab99b54e4a2"), "account" : "first", "connect" : "Always", "desc" : "first account feature first phase", "status" : true } /* 2 */ { "_id" : ObjectId("5e93fea32c804ab99b12e4d1"), "account" : "second", "connect" : "Sometimes", "desc" : "second account feature first phase", "status" : true } /* 3 */ { "_id" : ObjectId("5e93fea52f804ab99b55a7b1"), "account" : "first", "connect" : "Sometimes", "desc" :

Group by in mongoDB with property construction

僤鯓⒐⒋嵵緔 提交于 2020-05-09 06:26:13
问题 I have a collection named Accounts like below data /* 1 */ { "_id" : ObjectId("5e93fea52f804ab99b54e4a2"), "account" : "first", "connect" : "Always", "desc" : "first account feature first phase", "status" : true } /* 2 */ { "_id" : ObjectId("5e93fea32c804ab99b12e4d1"), "account" : "second", "connect" : "Sometimes", "desc" : "second account feature first phase", "status" : true } /* 3 */ { "_id" : ObjectId("5e93fea52f804ab99b55a7b1"), "account" : "first", "connect" : "Sometimes", "desc" :

Group by in mongoDB with property construction

天涯浪子 提交于 2020-05-09 06:26:00
问题 I have a collection named Accounts like below data /* 1 */ { "_id" : ObjectId("5e93fea52f804ab99b54e4a2"), "account" : "first", "connect" : "Always", "desc" : "first account feature first phase", "status" : true } /* 2 */ { "_id" : ObjectId("5e93fea32c804ab99b12e4d1"), "account" : "second", "connect" : "Sometimes", "desc" : "second account feature first phase", "status" : true } /* 3 */ { "_id" : ObjectId("5e93fea52f804ab99b55a7b1"), "account" : "first", "connect" : "Sometimes", "desc" :

MongoDB - Comment Upvoting/Downvoting with Aggregation Pipeline

戏子无情 提交于 2020-05-09 06:13:43
问题 I'm trying to implement an upvote/downvote mechanism for comments (similar to the upvoting/downvoting mechanism found on reddit). I have a separate collection called commentReputation and the documents inside can look like this: { "_id" : ObjectId("5e5acb6d6034a879655c8819"), "commentId" : ObjectId("5e5983102328a83d1a4b541f"), "creationDate" : ISODate("2020-02-29T20:37:01.509Z"), "upvotes" : [ ObjectId("5e5983102328a83d1a4b53e7"), ObjectId("5e5983102328a83d1a4b53e4") ], "downvotes" : [

MongoDB - Comment Upvoting/Downvoting with Aggregation Pipeline

拜拜、爱过 提交于 2020-05-09 06:12:09
问题 I'm trying to implement an upvote/downvote mechanism for comments (similar to the upvoting/downvoting mechanism found on reddit). I have a separate collection called commentReputation and the documents inside can look like this: { "_id" : ObjectId("5e5acb6d6034a879655c8819"), "commentId" : ObjectId("5e5983102328a83d1a4b541f"), "creationDate" : ISODate("2020-02-29T20:37:01.509Z"), "upvotes" : [ ObjectId("5e5983102328a83d1a4b53e7"), ObjectId("5e5983102328a83d1a4b53e4") ], "downvotes" : [

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

how to use $groupby and transform distinct value mongodb

南楼画角 提交于 2020-04-30 06:28:29
问题 How to transform the data using $if $else groupby condition MongoDB? This playground should return two object who belongs to text with "tester 2" and "tester 3" also if I have multiple object in history collection it should also check with last object not will all object how it is possible So condition should say if history's date is $gt then main collection should return nothing else return the matched criteria data. db.main.aggregate([ { $lookup: { from: "history", localField: "history_id",

Converting MongoDB query to spring

放肆的年华 提交于 2020-04-30 06:26:59
问题 I got a big mongo script and working with spring boot. I need to execute it as either native query or using aggregation framework. I can write lookup , unwind , group in aggregation framework. But I dont know how to write nested $addFields , $map , $reduce , $arrayToObject , $floor , $multiply and $divide . For example, { $lookup: {} //lookup script }, { $unwind // unwind script }, { $addFields: { ans: { $reduce: { input: { $map: { input: "$ans", in: { $objectToArray: "$$this" } } },