Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我刚刚开始学习 MongoDb,并且在不同的查询方面遇到了一些问题。
例如,如果我运行查询
db.images.distinct('gallery')
我得到了预期的结果,但也得到了空字符串和空值。如何编写只返回非空值的查询?
谢谢
避免只null使用值$ne
null
db.images.distinct( "gallery" , { "gallery" : { $ne : null } } );
或通过使用$nin在数组中指定来避免"",等等。null
""
db.images.distinct( "gallery" , { "gallery" : { $nin : ["", null] } });