Created
August 17, 2018 22:11
-
-
Save boutell/db0ca16e4b6de7a592cb79a4ed4a700c to your computer and use it in GitHub Desktop.
mongodb query for first array element being "null" does not obey the usual "undefined properties match null" rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will find "bar" and "woo". But it does not find "foo". | |
(function() { | |
db.dropDatabase(); | |
db.docs.insert([{ | |
title: 'foo', | |
ids: [] | |
}, { | |
title: 'bar' | |
}, { | |
title: 'baz', | |
ids: [ 5 ] | |
}, { | |
title: 'woo', | |
ids: [ null ] | |
}]); | |
})(); | |
data(db.docs.find({ 'ids.0': null }).toArray()); | |
function data(o) { | |
print(JSON.stringify(o, null, ' ') + '\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment