简体   繁体   English

如何查询具有空白列表的文档?

[英]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 http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24size

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何查询mongodb中所有没有特定ID的文档? - How to query all documents in mongodb that do not have a specific id? 如何根据相关文档查询MongoDB集合(在教义中) - How do I query MongoDB collection based on related documents (in Doctrine) 如何按匹配查询的数组中元素的数量排序文档? - How do I order documents by the number of elements in an array that match a query? MongoDB:如何查询一系列文档/词典中的元素数量? - MongoDB: How do I query for the number of elements in an array of documents/dictionaries? 如何通过引用的文档查询嵌入的文档? - How do I query embedded documents by a referenced document? 如何查询包含特定键/值对的文档 - How do I query for documents that contain a specific key/value pair 如何指定从查询中排除文档的条件? - How do I specify criteria for excluding documents from a query? 我如何找到那些特定字段与任何其他文档匹配(具有相同值)的文档 - How do i find those documents whose particular fields matches with any other documents(have the same value) 如何列出集合中的所有文档,但显示单个属性? - How do I list all documents in a collection but show a single property? 如何在MongoDB中编写查询,使我获得包含所有指定嵌套文档的所有文档? - How do I write a query in MongoDB that gives me all documents that contain all specified nested documents?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM