David John Smith
David John Smith

Reputation: 1864

RavenDB index/query documents where field does not exist

I have a collection of documents called Message. As part of a migration operation, I'm setting a timestamp on records that migrated, e.g.

...
new PatchRequest
{
    Type = PatchCommandType.Set,
    Name = "MigratedDateTime",
    Value = DateTime.UtcNow
},
...

I can create an index on the field MigratedDateTime, MigratedDateTime:[2016-02-11 TO 2016-02-12] but I cannot figure out how to find documents where this field is not set at all. Is this possible? If so, what would the lucene query look like?

Thanks

Upvotes: 0

Views: 921

Answers (2)

Ken Watson
Ken Watson

Reputation: 33

I know this is an old post, but in RavenDB 5.0 you can just do

from tablename group by MigratedDateTime where MigratedDateTime != null

not sure whether it executes more efficiently, but it is much easier.

Upvotes: 0

Ayende Rahien
Ayende Rahien

Reputation: 22956

You need to define an index, that index would have something like:

Migrated = doc.MigratedDateTime != null

Then you can query on Migrated:false

Upvotes: 2

Related Questions