集約フレームワークを使用して、配列内の各要素のインデックスをサブドキュメント自体に追加したいと考えています。
後の段階で$unwind
要素を取得したいのですが、myResults Array 内の古いインデックスが必要です。
現在の構造:
{ myResults : [
{ foo: "bar"
},
{ answer: 42
}
]
対象構造:
{ myResults : [
{ index: 0, // <-- this should be added
foo: "bar"
},
{ index: 1, // <-- this should be added
answer: 42
}
]
注:要素を更新したくありません。集約パイプラインの後の段階でインデックスを使用したいだけです。