What is the difference between null and “”…
I entered the following query and received a lot of “” in the result.
db.trips.find({“birth year”: {"$ne": null}}, {“birth year”:1}).sort({“birth year”: -1})
Then I tried
MongoDB Enterprise atlas-r754o0-shard-0:PRIMARY> db.trips.find({“birth year”: {"$ne": " "}}, {“birth year”:1}).sort({“birth year”: -1})
Then I tried
db.trips.find({“birth year”: {"$ne": “”}}, {“birth year”:1}).sort({“birth year”: -1})
It wasn’t until I used the last one that the null or blank entries were filtered out.
Also… I was always taught that you don’t want nulls… Is this enforcement of not allowing nulls in mongodb a good practice?
If I was writing this to check for nulls and blanks would I chain them together like this
db.trips.find({"$or": [{“birth year”: {"$ne": “”}}, {“birth year”: {"$ne": null}}, {“birth year”:1})].sort({“birth year”: -1})