# unwind
将文档中的某一个数组类型字段拆分成多条,每条包含数组中的一个值。
~~~
{ "_id" : 1, "item" : "ABC1", sizes: [ "S", "M", "L"] }
~~~
使用:
~~~
db.inventory.aggregate( [ { $unwind : "$sizes" } ] )
~~~
返回结果:
~~~
{ "_id" : 1, "item" : "ABC1", "sizes" : "S" }
{ "_id" : 1, "item" : "ABC1", "sizes" : "M" }
{ "_id" : 1, "item" : "ABC1", "sizes" : "L" }
~~~