Chapter 5: When to use null & when to use "" when both values are int32

Hi,

I was performing an exercise on sort & limit for the chapter 5, first field name that I was trying to sort i.e. “founded_year” had some null values in the document, hence added a condition $ne:null & it worked the data-type of this field was Int32, however for the second database the field name was “birth year” (again having data-type = Int32) but condition$ne:null did not work, I managed to get the answer but surprised to see that I had to use syntax “” instead of null, the only difference I can find in the field names is one had an underscore where null worked & the one having a space i.e. “birth year” did not accept null as value, following is the snapshot:

Does this help?

The { item : null } query matches documents that either contain the item field whose value is null or that do not contain the item field.

You see the documents because the value isn’t null (but an empty string.)

This is, strictly null or missed, not falsy values.

Hi @Santiago_Miranda,

Thanks for your reply, it does make sense, however when do we use {item : “”}?

There were two collections that I was querying for one it returned results when I used {item : null} for the other I used {item : “”} isn’t there a common command to get all blank cells whether or not null i.e. similar to SQL. Sorry if I am asking a dumb question, as I have extensively used SQL, now learning NoSQL :smiley:

Including @yulia_genkina just in-case she can answer this question.

Regards,
Punya

Sure you’ll get better insights. As for now, I guess you can use $nin:[null, ""]. Or $in:[null, ""] depending on what you want to see.

1 Like