nulls showing up as values in query

33 views
Skip to first unread message

ml.se...@medialabinc.com

unread,
Oct 17, 2016, 11:17:02 AM10/17/16
to RavenDB - 2nd generation document database
We have data where a null in the field indicate that it's a top level item. However, we cannot consistently query against nulls.

For example given an object like this

public class TestObj
{
public long Id { get; set; }
public long? Parent { get; set}
}

and a query of (using LinqPad)

Query<TestObj>().
Where(x => x.Parent != null);

We get the expected results
IdParent
330
161   0
1620
1630
164163
1931
2251
2261
2890
3211
4171
4491
4811

However, the opposite does not work. A query of

Query<TestObj>().
Where(x => x.Parent == null);
or

Query<TestObj>().
Where(x => !x.Parent.HasValue);

Returns 0 records even though TestObjs/1 has a null value for Parent.

{
    "Parent": null
}



Anyone know what might be going on here?

Tal Weiss

unread,
Oct 17, 2016, 12:59:44 PM10/17/16
to RavenDB - 2nd generation document database

What client version are you using and what server version?
Can you check through fiddler what is sent to the server? I believe your query should look something like this : Parent:[[NULL_VALUE]]


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ml.se...@medialabinc.com

unread,
Oct 17, 2016, 2:05:25 PM10/17/16
to RavenDB - 2nd generation document database
#30156 for the Client / Server build.

I'm using LinqPad for this particular query, and it doesn't seem to route through Fiddler so I can't see the queries. The other place it's located is inside a controller on a server (although not using test objects) so unless I do a reverse proxy I won't be able to see the actual requests.

Tal Weiss

unread,
Oct 17, 2016, 2:14:22 PM10/17/16
to RavenDB - 2nd generation document database

There should not be any problem querying for null values as you are doing. Are you able to reproduce this in an isolated test?


On Oct 17, 2016 21:05, <ml.se...@medialabinc.com> wrote:
#30156 for the Client / Server build.

I'm using LinqPad for this particular query, and it doesn't seem to route through Fiddler so I can't see the queries. The other place it's located is inside a controller on a server (although not using test objects) so unless I do a reverse proxy I won't be able to see the actual requests.

--

ml.se...@medialabinc.com

unread,
Oct 17, 2016, 2:38:27 PM10/17/16
to RavenDB - 2nd generation document database
I created a simplified test on Raven's test server and, of course, it works perfectly fine. (http://live-test.ravendb.net RallenTest) The real object we're using is more complex than the one I'm showing, and the resulting data sets have client data, so I can't put it out here, but the behavior is how I described.

It's... frustrating. We can get around it by assigning 0 instead of null, but that sets my OCD on edge.

Tal Weiss

unread,
Oct 17, 2016, 3:23:04 PM10/17/16
to RavenDB - 2nd generation document database

Well, it is hard to tell what's going on without having the data. Is there a chance the index is stale? Was there a dirty shutdown of the server? Can you generate the same index under a different name and query it when it is not stale (it might be that the index for corrupted due to dirty shutdown).
Does that problem happen on a specific document or all of the documents whom their parent is null? If it's all of then can you share the index definition and the c# classes used in the index (including the ones been loaded)?


--

ml.se...@medialabinc.com

unread,
Oct 17, 2016, 3:32:04 PM10/17/16
to RavenDB - 2nd generation document database
No doubt, it's frustrating. We're having the exact same problem with the User documents. Internal users don't have a client assigned to them, so their ClientId is null. But if we search for null clientIds, we get no records.

I copied my user account object into the public test DB and of course, it works fine. If i point the exact same query to the exact same object on our development server, it won't find me.

ml.se...@medialabinc.com

unread,
Oct 17, 2016, 3:38:59 PM10/17/16
to RavenDB - 2nd generation document database
I did get Fiddler to work. Turns out, I had forgotten I hid all raven calls since they cluttered up the fiddler window.

http://[internalurl]/databases/BuilderProducts/indexes/dynamic/Users?&query=ClientId%3A%5B%5BNULL_VALUE%5D%5D&pageSize=128


returns my "User" object just fine.

Tal Weiss

unread,
Oct 17, 2016, 3:41:15 PM10/17/16
to RavenDB - 2nd generation document database

Can you add the raw query too?


Maxim Buryak

unread,
Oct 18, 2016, 2:57:59 AM10/18/16
to rav...@googlegroups.com
Can you please check if you have numeric (or any other) sort defined on the field in question



Best Regards,

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Maxim Buryak l Core Team Developer Mobile:+972-54-217-7751

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

RavenDB paving the way to "Data Made Simplehttp://ravendb.net/  


ml.se...@medialabinc.com

unread,
Oct 18, 2016, 7:50:22 AM10/18/16
to RavenDB - 2nd generation document database
That was it, Maxim. There were auto created indexes that had sorts on those fields. Once I killed those indexes, everything started working.

My concern is that those indexes will auto create again. I saw older posts from eons ago about Raven having issues with null values on sorted fields, how do I avoid this issue in the future? 

Thanks,
Robb


On Tuesday, October 18, 2016 at 2:57:59 AM UTC-4, Maxim Buryak wrote:
Can you please check if you have numeric (or any other) sort defined on the field in question



Best Regards,

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Maxim Buryak l Core Team Developer Mobile:+972-54-217-7751

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

RavenDB paving the way to "Data Made Simplehttp://ravendb.net/  



On Mon, Oct 17, 2016 at 10:41 PM, Tal Weiss <t...@ayende.com> wrote:

Can you add the raw query too?

On Oct 17, 2016 22:39, <ml.se...@medialabinc.com> wrote:
I did get Fiddler to work. Turns out, I had forgotten I hid all raven calls since they cluttered up the fiddler window.

http://[internalurl]/databases/BuilderProducts/indexes/dynamic/Users?&query=ClientId%3A%5B%5BNULL_VALUE%5D%5D&pageSize=128


returns my "User" object just fine.

--
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.

--
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.

Maxim Buryak

unread,
Oct 19, 2016, 8:24:46 AM10/19/16
to rav...@googlegroups.com

In that case, I would recommend using static indexes. The automatic mechanism will still be able to choose the right index.

*Raven/CreateAutoIndexesForAdHocQueriesIfNeeded config
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

ml.se...@medialabinc.com

unread,
Oct 19, 2016, 1:05:26 PM10/19/16
to RavenDB - 2nd generation document database
That's the approach we took.

Thanks for the hlp.
Reply all
Reply to author
Forward
0 new messages