On this page本页内容
Disambiguation消除歧义
The following page refers to the aggregation stage 下一页指的是聚合阶段$unset. $unset。For the update operator 有关更新运算符$unset, see $unset.$unset,请参阅$unset。
$unset¶New in version 4.2.版本4.2中的新功能。
Removes/excludes fields from documents.从文档中删除/排除字段。
$unset$project¶The $unset is an alias for the $project stage that removes/excludes fields:$unset是$project阶段的别名,用于删除/排除字段:
To remove/exclude a field or fields within an embedded document, you can use the dot notation, as in:要删除/排除嵌入文档中的一个或多个字段,可以使用点符号,如中所示:
or
Create a sample 使用以下文档创建一个样本books collection with the following documents:books集合:
The following example removes the top-level field 以下示例删除顶级字段copies:copies:
Alternatively, you can also use the following syntax:或者,也可以使用以下语法:
Either operation returns the following documents:任一操作都会返回以下文档:
The following example removes the top-level fields 以下示例删除顶级字段isbn and copies:isbn和copies:
The $unset operation outputs the following documents:$unset操作输出以下文档:
The following example removes the top-level field 以下示例删除了顶级字段isbn, the embedded field first (from the name document) and the embedded field warehouse (from the elements in the copies array):isbn、嵌入字段first(从名称文档中)和嵌入字段warehouse(从副本数组中的元素中):
The $unset operation outputs the following documents:$unset操作输出以下文档: