I am trying to delete documents older than a certain point in ravenDB. I am still unfamiliar with Lucene and am having a hard time constructing this query.
_Session.Advanced.DatabaseCommands.DeleteByIndex(
typeof(AssetsByExpirationDate).Name,
new IndexQuery()
{
Query = string.Format("ExpirationDate:[\"{0:MM/dd/yyyy}\" TO \"{1:MM/dd/yyyy}\"]", DateTime.MinValue, new DateTime(2012,6,1))
});
What is the correct syntax for the Query to delete items before a certain date?
You can build your query outside the DatabaseCommands IndexQuery and use Query.ToString() to populate the IndexQuery Query string as below :
Using this way and if you are not very familiar with lucene query syntax, RavenDb Query API build it for you as shown before by calling .ToString() and got the following Lucene formatted query string.
Note that deleting using DatabaseCommands does’t work with stale indexes. So be careful or use a standard lucene query to retrieve documents to delete and then perform a simple Session.Delete(asset) foreach documents to delete.
Pay attention to pagination, since Ravendb returns only 128 results by default.