Hi,
I hope you all are fine. I came with a problem that I want to calculate the documents of a customer on the bases of date filter(last 30 days from the postedDate field) and then if there are more or equal to 5 documents then add a new field in another collection with a true flag otherwise false ( datatype for this field should be boolean)
Here are some samples of documents for your ease.
Collection A
{
"accountId" : "0310100000041704",
"postedDate" : ISODate("2020-12-22T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041704",
"postedDate" : ISODate("2020-12-21T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041704",
"postedDate" : ISODate("2020-12-20T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041704",
"postedDate" : ISODate("2020-12-19T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041704",
"postedDate" : ISODate("2020-12-18T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041704",
"postedDate" : ISODate("2020-12-17T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041705",
"postedDate" : ISODate("2020-12-19T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041705",
"postedDate" : ISODate("2020-12-11T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041705",
"postedDate" : ISODate("2020-11-19T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041706",
"postedDate" : ISODate("2020-06-19T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041706",
"postedDate" : ISODate("2020-07-19T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041706",
"postedDate" : ISODate("2020-08-19T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041706",
"postedDate" : ISODate("2020-09-19T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041706",
"postedDate" : ISODate("2020-10-19T00:00:00Z"),
"reasonCodeSending" : null,
"reference" : "4cb103in41103",
"remarks" : null,
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
Collection B
{
"accountId" : "0310100000041704",
"remarks" : "B",
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041705",
"remarks" : "M",
"typeKey" : "C",
"valueDate" : "2020-07-09T00:00:00.000+04:00"
}
{
"accountId" : "0310100000041706",
"remarks" : "K",
"typeKey" : "C",
"valueDate" : "2020-08-09T00:00:00.000+04:00"
}
Expected Output
{
"accountId" : "0310100000041704",
"remarks" : "B",
"typeKey" : "C",
"valueDate" : "2020-06-09T00:00:00.000+04:00",
"target": "true"
}
{
"accountId" : "0310100000041705",
"remarks" : "M",
"typeKey" : "C",
"valueDate" : "2020-07-09T00:00:00.000+04:00",
"target": "false"
}
{
"accountId" : "0310100000041706",
"remarks" : "K",
"typeKey" : "C",
"valueDate" : "2020-08-09T00:00:00.000+04:00",
"target": "false"
}