5
votes

I am using the http api to query ravendb (so a LINQ query is not the solution to my question). My Product document looks like this:

{
  "editDate": "2012-08-29T15:00:00.846Z"
}

and I have the index:

from doc in docs.Product
select new { doc.editDate }

I want to query all documents before a certain date AND time. I can query on the DATE using this syntax:

editDate: [NULL TO 2012-09-17]

however I can't figure out how to query the time component as well. Any ideas?

2

2 Answers

5
votes

You can query that using:

 editDate: [NULL TO 2012-09-17T15:00:00.846Z]

If you care for a part of that, use:

 editDate: [NULL TO 2012-09-17T15:00]

Note that you might have to escape parts of the query, like so:

 editDate: [NULL TO 2012\-09\-17T15\:00]

For this to work you also need to ensure that the field is analysed. In Raven Studio - Add Field -> editDate, and set Indexing to Analyzed.

-1
votes

One way of working around this problem is to store the value not as a date but as the number of seconds since the unix epoch.

This results in a number that you can compare against with ease.

I am using javascript and the moment js library:

{
  "editDate": "2012-08-29T15:00:00.846Z",
  "editDateUnix": moment("2012-08-29T15:00:00.846Z").unix()
}

Any my index:

from doc in docs.Product
select new { doc.editDate, doc.editDateUnix }

and my lucene query:

"editDate: [NULL TO "+moment("2012-09-17").unix()+"]"