On this page本页内容
$objectToArray
¶New in version 3.4.4.3.4.4版新增。
Converts a document to an array. 将文档转换为数组。The return array contains an element for each field/value pair in the original document. 返回数组包含原始文档中每个字段/值对的一个元素。Each element in the return array is a document that contains two fields 返回数组中的每个元素都是一个包含两个字段k
and v
:k
和v
的文档:
k
field contains the field name in the original document.k
字段包含原始文档中的字段名。v
field contains the value of the field in the original document.v
字段包含原始文档中该字段的值。$objectToArray
has the following syntax:语法如下所示:
The <object>
expression can be any valid expression as long as it resolves to a document object. <object>
表达式可以是任何有效的表达式,只要它解析为文档对象。$objectToArray
applies to the top-level fields of its argument. $objectToArray
适用于其参数的顶级字段。If the argument is a document that itself contains embedded document fields, the 如果参数是本身包含嵌入文档字段的文档,$objectToArray
does not recursively apply to the embedded document fields.$objectToArray
不会递归应用于嵌入文档字段。
For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
$objectToArray
Example¶Consider a 考虑一个inventory
collection with the following documents:inventory
集合带有以下文档:
The following aggregation pipeline operation use the 以下聚合管道操作使用$objectToArray
to return the dimensions
field as an array:$objectToArray
将dimensions
字段作为数组返回:
The operation returns the following:该操作返回以下内容:
$objectToArray
Consider a 考虑一个inventory
collection with the following documents:inventory
集合带有以下文档:
The following aggregation pipeline operation uses the 下面的聚合管道操作使用$objectToArray
along with $unwind
and $group
to calculate the total items in stock per warehouse.$objectToArray
以及$unwind
和$group
来计算每个仓库的总库存。
The operation returns the following:该操作返回以下内容:
$objectToArray
+ $arrayToObject
Example¶Consider a 考虑一个inventory
collection with the following documents:inventory
集合带有以下文档:
The following aggregation pipeline operation calculates the total in stock for each item and adds to the 以下聚合管道操作计算每个项目的总库存,并将其添加到instock
document:instock
文档中:
The operation returns the following:该操作返回以下内容:
See also参阅