Ronald
Ronald

Reputation: 207

cts query to filter documents from a particular collection for the last 24 hours

I have been trying to find the documents from a particular collection based on the field report_time.

I have been trying the below query. But, it doesn't work.

cts.andQuery(cts.collectionQuery('myCollection'),cts.jsonPropertyRangeQuery("report_time", ">", new Date(Date.now() - 86400 * 1000).toISOString()))

Upvotes: 0

Views: 73

Answers (2)

asusu
asusu

Reputation: 321

You don't have to do the math, you can use an "age query". See the end of the page at https://docs.marklogic.com/guide/search-dev/rangequery

Upvotes: 0

Mads Hansen
Mads Hansen

Reputation: 66781

From that snippet, the one thing that needs adjustment is that the query criteria need to be in an array for the cts.andQuery() param:

cts.andQuery([
  cts.collectionQuery('myCollection'),
  cts.jsonPropertyRangeQuery("report_time", ">", new Date(Date.now() - 86400 * 1000).toISOString())
])

Upvotes: 1

Related Questions