I'm just beginning to learn MongoDb and am having some problems with distinct queries.
If I for instance run the query
db.images.distinct('gallery')
I get the expected result, but also empty strings and null values. How can I write a query that just returns the values that are not null?
Thanks
to avoid only null
values use $ne
db.images.distinct( "gallery" , { "gallery" : { $ne : null } } );
or avoid ""
,null
and more by specifying in an array using $nin.
db.images.distinct( "gallery" , { "gallery" : { $nin : ["", null] } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With