Map = @"from doc in docs.Customers select new { Name = doc.Name, Age = ((decimal)doc.Age), CaughtDate = doc.Inner.ContainsKey(""CaughtDate"") ? doc.CaughtDate : ""[MISSING_FIELD]"" })"
var missingFieldMatches = session.Advanced.LuceneQuery<CustomerV1>("CustomerIndex") .WhereEquals("CaughtDate", @"[MISSING_FIELD]") .ToList();
var nullMatches = session.Query<CustomerV2>("CustomerIndex") .Where(x => x.CaughtDate == null) .ToList();
But I think it would be nicer if RavenDB handled some or all of it for you, kinda like the way it does for null values at the moment. So I'm not saying this is a elegant workaround, just that it's possible ;-)
from doc in docs.Customers select new { Name = doc.Name,
Age = doc.Age, CaughtDate = doc.CaughtDate.StoreMissingFieldInIndex() })"
Guys,RavenDB has different behavior for missing vs. null.users/1 - { "Name": "A" }users/2 - { "Name": "B", "StoppedBeatingTheWife": false }users/3 - { "Name": "C", "StoppedBeatingTheWife": true }users/1 - { "Name": "D", "StoppedBeatingTheWife": null }Now, let us see what sort of queries we can do on this data set.Note that "StoppedBeatingTheWife" is a boolean (non nullable) property. I intentionally choose a this example, mind.Now, what should be the behavior of asking "give all users who stopped beating their wives?"StoppedBeatingTheWife:true would return CStoppedBeatingTheWife:false would return BNow, we may have users that declined to answer, in which case we can do:StoppedBeatingTheWife:[[NULL_VALUE]] and get DBut in the case of A, it isn't that the value is null, is it that there isn't a value at all.We can't check for null equality. In most cases, it is a sign of schema migration, but we have a lot of users that use RavenDB for sparse schema, in which null properties are simply not written to the document.And even if it is just additional property, RavenDB doesn't know what to put it, and null isn't appropriate, since it is already a valid value.As a result, we make a distinction between null the value and missing value.You can't do a query on a missing field, but you can query on its absence.
Map = @"from doc in docs.Users
select new { Name = doc.Name,
StoppedBeatingTheWifeExists = doc.StoppedBeatingTheWife != null
})"
Map = @"from doc in docs.Users
select new { Name = doc.Name,
StoppedBeatingTheWifeExists = doc.Inner.ContainsKey(""StoppedBeatingTheWife"") ? true : false, })"
Guys,RavenDB has different behavior for missing vs. null.users/1 - { "Name": "A" }users/2 - { "Name": "B", "StoppedBeatingTheWife": false }users/3 - { "Name": "C", "StoppedBeatingTheWife": true }users/1 - { "Name": "D", "StoppedBeatingTheWife": null }Now, let us see what sort of queries we can do on this data set.Note that "StoppedBeatingTheWife" is a boolean (non nullable) property. I intentionally choose a this example, mind.Now, what should be the behavior of asking "give all users who stopped beating their wives?"StoppedBeatingTheWife:true would return CStoppedBeatingTheWife:false would return BNow, we may have users that declined to answer, in which case we can do:StoppedBeatingTheWife:[[NULL_VALUE]] and get DBut in the case of A, it isn't that the value is null, is it that there isn't a value at all.We can't check for null equality. In most cases, it is a sign of schema migration, but we have a lot of users that use RavenDB for sparse schema, in which null properties are simply not written to the document.And even if it is just additional property, RavenDB doesn't know what to put it, and null isn't appropriate, since it is already a valid value.As a result, we make a distinction between null the value and missing value.You can't do a query on a missing field, but you can query on its absence.
You need to check ON the exists field.
var plants = RavenSession.Advanced.LuceneQuery<ReleasedPlant, CaughtConfirmedNonArchivedPlantsIndex>().WhereEquals("CuaghtDateExists", true);
session.Advanced.LuceneQuery< ReleasedPlant, CaughtConfirmedNonArchivedPlantsIndex >().WhereEquals("CaughtDateExists", false).OrElse().WhereEquals(x=>x.CaughtDate, null).OrElse().WhereLessThan(x=>x.CaughtDate, DateTime.Today)
Let's say my document has not the Field "CaughtDate". I am doing an update of my web app where new documents are created with this field.
In a query, I want to get the documents that have the field set to null, lower than a specific date or that don't have the field.
The static index is like this:
Map = plants => from plant in plants
where (!plant.Status.Contains(ReleasedPlant.Status_Archived) && plant.Status.Contains(ReleasedPlant.Status_CaughtConfirmed) && plant.Enabled)
select new { CaughtDate = plant.CaughtDate };
My query is like this:
var plants = session.Query<ReleasedPlant, CaughtConfirmedNonArchivedPlantsIndex>()
.Where(x => (x.CaughtDate == null) || (x.CaughtDate < date));
--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.