Query last 10 days of data through MongoDB reader

Hi,

I had a query regarding MongoDb. How can I query in the MongoDB reader to get only the last 10 days of data ? I have a date time string in my table and i want to use that to filter the data only for the last 10 days.

Thanks.

Hi @Adeel_123 ,
Could you try the below nodes to get the date of the 10th (t-10) day from the current day and then use the variable to table row node, convert the (t-10) to a flow variable, and pass it to the date&time-based row filter?

I hope this helps. Let me know if you have any questions.

Thank you,
Sanket

2 Likes

Hi,
Thanks for the solution, but I was looking for how to do this within the MongoDB Reader Node. I have tons of data coming through MongoDB and I just want to read the latest 10 days of data through MongoDB Reader node.
Can you help with this please, thanks.

Hi,
I’m not an expert in No-SQL databases like MongoDB. But in the end its a matter of passing the right query. The exact query depends strongly on the data structure in the MongoDB.
In general in KNIME you can connect with the MongoDB connector and use the DB Reader Node to catch the data:
image

You can specify the query something like this (assuming the collections has a field “createdAt”):
“createdAt”: { “$gte”: { “$date”: “2023-12-20T00:00:00Z” } }

Of course this is static. To make this automatic you have to adjust this query string and pass it to the DB Reader node.

image

To make this dynamical you need to add some additional nodes.
First: catch current date
Second: substract 10 days from the execution date
Third: convert the date to a variable
Fourth: Create Query using the variable

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.