下面的$unwind操作使用includeArrayIndex选项在输出中包含数组索引。
db.inventory2.aggregate([ { $unwind: { path: "$sizes", includeArrayIndex: "arrayIndex" } }])