Check if collection contain todays data

620 views
Skip to first unread message

shashan...@flowian.com

unread,
Feb 25, 2020, 10:33:45 AM2/25/20
to Fujitsu RunMyProcess Developer Community
Hello,
I have a collection which has multiple records with data like below

{"_id":"34543dfdf23423fvd","email_id":"a...@asd.com","task_name":"AUDIT: ASD- request number (NOV/2/2015-0002)","user_serial_no":1,"comepleted_date_timestamp":1446470067647,"unique_id":"sada234d234234","assigned_date":"02/11/2015 01:09:33","contact_person":"asd","comepleted_date":"02/11/2015 01:14:27","user_name":"SDF","task_url":"https://live.runmyprocess.com","assigned_date_timestamp":1446469773702,"status":"Completed"},

How can i get the records from collection from task name key if it contains todays date using aggregate collection in freemarker.

Thanks & Regards,
Shashank

rmppku...@gmail.com

unread,
Feb 26, 2020, 3:09:55 AM2/26/20
to Fujitsu RunMyProcess Developer Community, shashan...@flowian.com
Hi Shashank,

To keep the query simple, please store date as string in a specific format i.e. "dd-MM-yy" or "MM-dd-yy" as "timestamp_str", this way you can easily apply the aggregate function via js or freemarker method only using the "match" operator as while converting the timestamp to date on Mongodb server it will contain a full date and you need to apply the date range ("gte" and "lt" operator) to get the required data.

Please refer to following link for more understanding:-



Also please refer to below link for more understanding on "date" aggregation.



Best Regards,
Pankaj Kumar
Fujitsu RunMyProcess Support

shashan...@flowian.com

unread,
Feb 26, 2020, 4:10:53 AM2/26/20
to Fujitsu RunMyProcess Developer Community, shashan...@flowian.com, rmppku...@gmail.com
Hello Pankaj,
Now i cannot change the collection column because it is used in many projects so can i use match function on this column "task_name":"AUDIT: ASD- request number (NOV/2/2015-0002)" and and get the data by passing string as NOV/2/2015.
Thanks & Regards,
Shashank

RunMyProcess Support

unread,
Feb 28, 2020, 4:30:40 AM2/28/20
to Fujitsu RunMyProcess Developer Community, shashan...@flowian.com, rmppku...@gmail.com
Hi Shashank,

Please refer below code to achieve this functionality:

<#assign current_date = "NOV/2/2015">
<#assign my_pipeline1>
{$project : {"task_name" : "$task_name", "task_match" : {$eq : [{$substr : ["$task_name",28,10]},"${current_date}"]}}}
</#assign>
<#assign res=aggregate_collection("practice_test",my_pipeline1)>
${res}

--- where "practice_test" is a collection name, "task_match" is the newly added key which will store boolean value based on date match. Here I have just kept "task_name" key-value pair in the record, you can add as many pairs you require.

From the result of this query, you can fetch records with "task_match = true", and it will give you the required result.

Kindly try this out and let us know if this works for you.

Best Regards,
Fujitsu RunMyProcess Support.



Reply all
Reply to author
Forward
0 new messages