MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1856字,纯文字阅读大概需要3分钟。
内容图文
![MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields](/upload/InfoBanner/zyjiaocheng/473/14e9ca72af6945fe839ad818ca9c495d.jpg)
The examples on this page use the db.collection.find() method in the mongo shell. To populate the users collection referenced in the examples, run the following in mongo shell:
db.users.insert( [ { "_id" : 900, "name" : null }, { "_id" : 901 } ] )
Equality Filter
The { name : null } query matches documents that either contain the name field whose value is null or that do not contain the name field.
Given the following query:
db.users.find( { name: null } )
The query returns both documents:
{ "_id" : 900, "name" : null } { "_id" : 901 }
If the query uses an index that is sparse, however, then the query will only match null values, not missing fields.
Changed in version 2.6: If using the sparse index results in an incomplete result, MongoDB will not use the index unless a hint() explicitly specifies the index. See Sparse Indexes for more information.
Type Check
The { name : { $type: 10 } } query matches documents that contains the name field whose value is null only; i.e. the value of the item field is of BSON Type Null (i.e. 10) :
db.users.find( { name : { $type: 10 } } )
The query returns only the document where the item field has a null value:
{ "_id" : 900, "name" : null }
Existence Check
The { name : { $exists: false } } query matches documents that do not contain the item field:
db.users.find( { name : { $exists: false } } )
The query returns only the document that does not contain the item field:
{ "_id" : 901 }
SEE ALSO: The reference documentation for the $type and $exists operators.
MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields
标签:utils href and collect missing title nts nbsp contain
本文系统来源:http://www.cnblogs.com/huey/p/6120495.html
内容总结
以上是互联网集市为您收集整理的MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields全部内容,希望文章能够帮你解决MongoDB - MongoDB CRUD Operations, Query Documents, Query for Null or Missing Fields所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。