Skip to main content

I'm trying to fetch records from MongoDB with "Execute Command" and code snippet as below and ISO date feature is not working. Let me know alternate solution to execute below DW .

%dw 2.0

 

import * from dw::core::Periods

 

output application/json

 

---

 

{

 

"aggregate": "User",

 

"pipeline": [

 

{

 

"\$match": {

 

"created_at": {

 

"\$gte": 'ISODate(' ++(now() - |P1D| - minutes(5)) ++ ')' as String {

 

"format": "yyyy-MM-dd'T'hh:mm:ss'Z'"

 

}

 

}

 

}

 

}],

 

"cursor": {

 

}

 

}

7 Antworten
  1. 21. Nov. 2024, 17:18

    @Jjj Rock​ 

    I have achieved this without using any execute command using ISO date format as follows, ISO date format is working in mongo if we send in proper format as follows where "date_modified" is my field name in mongodb

     

    Transform Payload for the mongo query:

    {

     "\$expr": {

      "\$gte": [

       "\$date_modified",

       { "\$toDate": "2024-11-20T11:56:14.000+00:00" }

      ]

     }

    }

     

    sample flow which is working as follows :

    <flow name="GetRecordsWithDate" doc:id="3a18e2ea-466b-4d30-ab26-dc56e1e8b910">

    <scheduler doc:name="Scheduler" doc:id="aae27461-6164-46b0-8818-06a6dc41024c">

    <scheduling-strategy>

    <fixed-frequency timeUnit="HOURS" />

    </scheduling-strategy>

    </scheduler>

    <ee:transform doc:name="Transform Message" doc:id="dc2bd055-977e-4133-ae6b-2b37d42cb242" >

    <ee:message >

    <ee:set-payload ><![CDATA[%dw 2.0

    output application/json

    ---

    {

    "\$expr": { "\$gte": ["\$date_modified", { "\$toDate": '2024-11-20T11:56:14.000+00:00' } ] }

    }]]></ee:set-payload>

    </ee:message>

    </ee:transform>

    <mongo:find-documents doc:name="Find documents" doc:id="27734fbb-9669-4f33-bb92-96f26df51a3b" config-ref="MongoDB_Config" collectionName="collectionName" fields=",">

    <mongo:query ><![CDATA[#payload]]></mongo:query>

    </mongo:find-documents>

     

    <!-- Use DataWeave to extract distinct IDs -->

    <ee:transform doc:name="Transform Message" doc:id="2c99f8b6-1b2f-4ce9-b8b7-56086fbc28d5" >

    <ee:message >

    <ee:set-payload resource="transformations/distinct_avails_all_titles_alpha_rl_ids.dwl" />

    </ee:message>

    </ee:transform>

    </flow>

0/9000