简体   繁体   中英

How do I query for documents that have a blank list?

db.users.find({'friends':[]});

This doesn't work! I want documents that do not have anyone in "friends" attribute.

您可以使用$ size运算符轻松实现:

db.users.find({'friends': { $size: 0 }});

Try

db.users.find({'friends': {$size : 0}});

You can read about it here:

http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24size

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM