This page provides examples in:本页提供了以下示例:
Different query operators in MongoDB treat MongoDB中的不同查询运算符对null values differently.null值的处理方式不同。
This page provides examples of operations that query for 此页面提供了使用null values using the db.collection.find() method in the mongo shell. mongo shell中的db.collection.find()方法查询null值的操作示例。The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for 本页提供了使用MongoDB Compass查询null values using MongoDB Compass. null值的操作示例。The examples on this page use the 本页上的示例使用库存集合。inventory collection. Populate the 使用以下文档填充inventory collection with the following documents:inventory集合:
This page provides examples of operations that query for null values using the pymongo.collection.Collection.find() method in the PyMongo Python driver. The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for 本页提供了使用mongodb Java同步驱动程序中的null values using the com.mongodb.client.MongoCollection.find method in the MongoDB Java Synchronous Driver.com.mongodb.client.MongoCollection.find方法查询空值的操作示例。
Tip
The driver provides com.mongodb.client.model.Filters helper methods to facilitate the creation of filter documents. 驱动程序提供com.mongodb.client.model.Filters帮助程序方法,以方便创建筛选文档。The examples on this page use these methods to create the filter documents.本页上的示例使用这些方法创建筛选文档。
The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for null values using the Collection.find() method in the MongoDB Node.js Driver. The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for null values using the MongoDB\Collection::find() method in the MongoDB PHP Library. The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for null values using the motor.motor_asyncio.AsyncIOMotorCollection.find() method in the Motor driver. The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for 此页面提供了使用mongodb Java反应流驱动程序中的null values using the com.mongodb.reactivestreams.client.MongoCollection.find method in the MongoDB Java Reactive Streams Driver.com.mongodb.reactivestreams.client.MongoCollection.find方法查询null值的操作示例。
The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for null values using the MongoCollection.Find() method in the MongoDB C# Driver. The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for null values using the MongoDB::Collection::find() method in the MongoDB Perl Driver. The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for null values using the Mongo::Collection#find() method in the MongoDB Ruby Driver. The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for null values using the collection.find() method in the MongoDB Scala Driver. The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
This page provides examples of operations that query for null values using the Collection.Find function in the MongoDB Go Driver. The examples on this page use the 本页上的示例使用inventory collection. inventory集合。To populate the 要填充inventory collection, run the following:inventory集合,请运行以下操作:
Important
Use None with the PyMongo Python driver to query for null or missing fields in MongoDB.
Important
Use None with the Motor driver to query for null or missing fields in MongoDB.
Important
Use BsonNull.Value with the MongoDB C# driver to query for null or missing fields in MongoDB.
Important
Use undef with the MongoDB Perl driver to query for null or missing fields in MongoDB.
Important
Use nil with the MongoDB Ruby driver to query for null or missing fields in MongoDB.
Important
Use BsonNull() with the MongoDB Scala driver to query for null or missing fields in MongoDB.
Important
Use nil with the MongoDB Go driver to query for null or missing fields in MongoDB.
You can run the operation in the web shell below:您可以在下面的web shell中运行该操作:
For instructions on inserting documents in MongoDB Compass, see Insert Documents.有关在MongoDB Compass中插入文档的说明,请参阅插入文档。
The { item : null } query matches documents that either contain the item field whose value is null or that do not contain the item field.{ item : null }查询匹配包含值为null的item字段或不包含item字段的文档。
The { item : null } query matches documents that either contain the item field whose value is null or that do not contain the item field.{ item : null }查询匹配包含值为null的item字段或不包含item字段的文档。
The { item : None } query matches documents that either contain the item field whose value is null or that do not contain the item field.
The eq("item", null) query matches documents that either contain the item field whose value is null or that do not contain the item field.eq("item", null)查询匹配包含值为null的item字段或不包含item字段的文档。
The { item : null } query matches documents that either contain the item field whose value is null or that do not contain the item field.{ item : null }查询匹配包含值为null的item字段或不包含item字段的文档。
The [ item => undef ] query matches documents that either contain the item field whose value is null or that do not contain the item field.
The { item : None } query matches documents that either contain the item field whose value is null or that do not contain the item field.
The eq("item", null) query matches documents that either contain the item field whose value is null or that do not contain the item field.eq("item", null)查询匹配包含值为null的item字段或不包含item字段的文档。
The Eq("item", BsonNull.Value) query using the FilterDefinitionBuilder.Eq() method matches documents that either contain the item field whose value is null or that do not contain the item field.
The { item => undef } query matches documents that either contain the item field whose value is null or that do not contain the item field.
The { item => nil } query matches documents that either contain the item field whose value is nil or that do not contain the item field.
The equal("item", BsonNull) query matches documents that either contain the item field whose value is null or
that do not contain the item field.
The item => nil query matches documents that either contain the item field whose value is nil or that do not contain the item field.
The query returns both documents in the collection.查询将返回集合中的两个文档。
The { item : { $type: 10 } } query matches only documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :{ item : { $type: 10 } }查询只匹配包含值为null的item字段的文档;亦即,item字段的值为BSON类型Null(类型编号10):
The { item : { $type: 10 } } query matches only documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :{ item : { $type: 10 } }查询只匹配包含值为null的item字段的文档;亦即,item字段的值为BSON类型Null(类型编号10):
The { item : { $type: 10 } } query matches only
documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :
The type("item", BsonType.NULL) query matches only
documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :type("item", BsonType.NULL)查询只匹配包含值为NULL的item字段的文档;亦即,item字段的值为BSON类型Null(类型编号10):
The { item : { $type: 10 } } query matches only
documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :{ item : { $type: 10 } }查询只匹配包含值为null的item字段的文档;亦即,item字段的值为BSON类型Null(类型编号10):
The [ item => [ $type => 10 ] ] query matches only
documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :
The { item : { $type: 10 } } query matches only
documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :
The type("item", BsonType.NULL) query matches only
documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :type("item", BsonType.NULL)查询只匹配包含值为NULL的item字段的文档;亦即,item字段的值为BSON类型Null(类型编号10):
The Type("item", BsonType.Null) query using the FilterDefinitionBuilder.Type() method matches only documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :
The { item => { $type => 10 } } query matches only
documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :
The { item => { $type => 10 } } query matches only
documents that contain the item field whose value is null; i.e. the value of the item field is of BSON Type Null (type number 10) :
The following query matches only
documents that contain the item field whose value is of BSON Type Null (type number 10) :
The query returns only the document where the 查询仅返回项目字段值为item field has a value of null.null的文档。
The following example queries for documents that do not contain a field. 以下示例查询不包含字段的文档。[1]
The { item : { $exists: false } } query matches documents that do not contain the item field:{ item : { $exists: false } }查询匹配不包含item字段的文档:
The { item : { $exists: false } } query matches documents that do not contain the item field:{ item : { $exists: false } }查询匹配不包含item字段的文档:
The { item : { $exists: False } } query matches documents that do not contain the item field:
The exists("item", false) query matches documents that do not contain the item field:exists("item", false)查询匹配不包含item字段的文档:
The { item : { $exists: false } } query matches documents that do not contain the item field:{ item : { $exists: false } }查询匹配不包含item字段的文档:
The [ item => [ $exists => false ] ] query matches documents that do not contain the item field:
The { item : { $exists: False } } query matches documents that do not contain the item field:
The exists("item", false) query matches documents that do not contain the item field:exists("item", false)查询匹配不包含item字段的文档:
The Exists("item", false) query using the FilterDefinitionBuilder.Exists() method matches documents that do not contain the item field:
The { item => { $exists => false } } query matches documents that do not contain the item field:
The { item => { $exists => false } } query matches documents that do not contain the item field:
The exists("item", exists = false) query matches documents that do not contain the item field:
The query only returns the document that does not contain the 查询只返回不包含item field.item字段的文档。
| [1] | $type: 0 as a synonym for $exists:false. $type:0用作$exists:false的同义词。 |