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.