'How to check if the MongoDB value is Null (or not) in JavaScript
Given the following document in a valid MongoDB query, how can I check the value of name to see if it's Null ?
{
"_id" : {
"userId" : "2a4c18a7-e12c-4f58-a08c-17f52a01d3a0"
},
"name" : null
}
I've omitted other fields (not relevant to this question). Notice how the name field has a null value? This is legit .. meaning ... I can't change my mongo query to filter out these. Some of the documents returned back will have a null value.
Here is what the field looks like, in Studio3T:

So is there a way to check this value, in JavaScript?
I tried the following, which failed to work:
let usersCursor = usersCollection.find(<some query>);
usersCursor.forEach(user => {
if (user.name === null)
{
// Then do something. This code is never called.
};
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
