4

我刚刚开始学习 MongoDb,并且在不同的查询方面遇到了一些问题。

例如,如果我运行查询

db.images.distinct('gallery') 

我得到了预期的结果,但也得到了空字符串和空值。如何编写只返回非空值的查询?

谢谢

4

1 回答 1

18

避免只null使用值$ne

db.images.distinct( "gallery" , { "gallery" : { $ne : null } } );

或通过使用$nin在数组中指定来避免"",等等。null

db.images.distinct( "gallery" , { "gallery" : { $nin : ["", null] } });
于 2013-04-22T11:34:26.483 回答