Skip to content

Instantly share code, notes, and snippets.

@boutell
Created August 17, 2018 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boutell/db0ca16e4b6de7a592cb79a4ed4a700c to your computer and use it in GitHub Desktop.
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 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