aggregation-framework

MongoDb Aggregate , find duplicate records within 7 days

假装没事ソ 提交于 2020-03-04 21:36:20
问题 I have to create a check for this use case- Duplicate payment check • Same amount to a same account number in last 7 days for all transactions. I haven't used mongoDb as much would have been easier for me to write in sql This is what I am trying without the 7 days part db.transactiondetails.aggregate({$group: {"_id":{"account_number":"$account_number","amount":"$amount"},"count": { $sum: 1 }}}) Where I get something like this : { "_id" : { "account_number" : "xxxxxxxy", "amount" : 19760 },

MongoDb Aggregate , find duplicate records within 7 days

时间秒杀一切 提交于 2020-03-04 21:35:50
问题 I have to create a check for this use case- Duplicate payment check • Same amount to a same account number in last 7 days for all transactions. I haven't used mongoDb as much would have been easier for me to write in sql This is what I am trying without the 7 days part db.transactiondetails.aggregate({$group: {"_id":{"account_number":"$account_number","amount":"$amount"},"count": { $sum: 1 }}}) Where I get something like this : { "_id" : { "account_number" : "xxxxxxxy", "amount" : 19760 },

Lookup and sort the foreign collection

删除回忆录丶 提交于 2020-03-03 10:25:13
问题 so I have a collection users , and each document in this collection, as well as other properties, has an array of ids of documents in the other collection: workouts . Every document in the collection workouts has a property named date . And here's what I want to get: For a specific user, I want to get an array of {workoutId, workoutDate} for the workouts that belong to that user, sorted by date. This is my attempt, which is working fine. Users.aggregate([ { $match : { _id : ObjectId(

Nested $addFields in MongoDB

北战南征 提交于 2020-03-03 08:46:26
问题 I have the following document: [ { "callId": "17dac51e-125e-499e-9064-f20bd3b1a9d8", "caller": { "firstName": "Test", "lastName": "Testing", "phoneNumber": "1231231234" }, "inquiries": [ { "inquiryId": "b0d14381-ce75-49aa-a66a-c36ae20b72a8", "routeHistory": [ { "assignedUserId": "cfa0ffe9-c77d-4eec-87d7-4430f7772e81", "routeDate": "2020-01-01T06:00:00.000Z", "status": "routed" }, { "assignedUserId": "cfa0ffe9-c77d-4eec-87d7-4430f7772e81", "routeDate": "2020-01-03T06:00:00.000Z", "status":

How can I implement addFields mongoDB query in Java

断了今生、忘了曾经 提交于 2020-02-28 06:28:49
问题 I have found several example at StackOverFlow related to addFields in Aggregation. But no one implemented in Java. db.getCollection('myDocument').aggregate([ {$match : {"metaId.ref.uuid" : "d6112808-1ce1-4545-bd52-cf55bc4ed25e"}}, {$lookup: {from: "simple", localField: "someId.ref.uuid", foreignField: "uuid", as: "simple"}}, {"$unwind": "$simple"}, {"$addFields": { "metaId.ref.name" : "$simple.name" }} ]) I am not able to Implement In Java Correctly:-- Not getting proper procedure

How can I implement addFields mongoDB query in Java

末鹿安然 提交于 2020-02-28 06:28:24
问题 I have found several example at StackOverFlow related to addFields in Aggregation. But no one implemented in Java. db.getCollection('myDocument').aggregate([ {$match : {"metaId.ref.uuid" : "d6112808-1ce1-4545-bd52-cf55bc4ed25e"}}, {$lookup: {from: "simple", localField: "someId.ref.uuid", foreignField: "uuid", as: "simple"}}, {"$unwind": "$simple"}, {"$addFields": { "metaId.ref.name" : "$simple.name" }} ]) I am not able to Implement In Java Correctly:-- Not getting proper procedure

$lookup for aggregation for two layer relationship

一个人想着一个人 提交于 2020-02-25 03:41:18
问题 Let me preface this by saying I may have not designed the User and corporation relationship correctly by not denormalizing, but how can I do it with what I have? Lets say I have the following document in my collection Classes Collecton { "_id": ObjectId("5df58d45244a850d54b922c8"), "mentors" : { "numOfMentors" : NumberInt(1), "mentorList" : [ ObjectId("5c9ba636347bb645e0865283") ] }, "lessons": [ { "_id": ObjectId("5db221be211d7b68ac8be618"), "mentorData": { "objective": "Ensuring students

Convert Date to String in nested array in mongodb

好久不见. 提交于 2020-02-25 01:05:11
问题 I have a mongodb collection called cases and inside cases I have an array of cases per company object. So the structure is: Inside each case I want to use the createddate (which is a string) and endDate (also string) and convert it to a mongodb date. When I use NoSQLBooster I add the following query: db.cases.aggregate([ { $match: { companyID: 218 }}, { $unwind: "$cases" }, { $match: { 'cases.id': '299' }}, { $addFields: { 'cases.created': new Date('2010-06-21T00:00:00.000'), 'cases.closed':

MongoDb sort is slow with lookup collections

和自甴很熟 提交于 2020-02-24 18:36:09
问题 I have two collections in my mongodb database as follows: employee_details with approximately 330000 documents which has department_id as a reference from departments collection departments collections with 2 fields _id and dept_name I want to join the above two collections using department_id as foreign key by using lookup method. Join works fine but the mongo query execution takes long time when I add sort. Note: The execution is fast If I remove the sort object or If I remove the lookup

MongoDb sort is slow with lookup collections

[亡魂溺海] 提交于 2020-02-24 18:35:47
问题 I have two collections in my mongodb database as follows: employee_details with approximately 330000 documents which has department_id as a reference from departments collection departments collections with 2 fields _id and dept_name I want to join the above two collections using department_id as foreign key by using lookup method. Join works fine but the mongo query execution takes long time when I add sort. Note: The execution is fast If I remove the sort object or If I remove the lookup