Mongo 集計からネストされた配列のこの結果を取得できます。
"vals": [
[ [ { "reference_date": "2013-09-01", "price": 79 },
{ "reference_date": "2013-09-02", "price": 69 },
{ "reference_date": "2013-09-03", "price": 101 }, ] ],
[ [ { "reference_date": "2013-08-01", "price": 101 },
{ "reference_date": "2013-08-02", "price": 106 },
{ "reference_date": "2013-08-03", "price": 101 }, ] ],
[ [ { "reference_date": "2013-07-01", "price": 129 },
{ "reference_date": "2013-07-02", "price": 163 },
{ "reference_date": "2013-07-03", "price": 192 }, ] ],
]
私はこのクエリを使用しています:
coll.aggregate([
{ $match: { 'account_id': '123', }, },
{ $group: {
_id: { 'account': '$account_id' },
vals: { $push: '$data.prices' } }, },
]);
私の基本ドキュメントは次のようになります。
{'account_id': '123',
. . . other stuff . . .
'data': [{
'prices': [
{ "reference_date": "2013-08-01", "price": 101 },
{ "reference_date": "2013-08-02", "price": 106 },
{ "reference_date": "2013-08-03", "price": 101 },
],
. . . other stuff under data key . . .
}]
ネストされた配列が単一の配列に結合され、オブジェクト項目のみを保持するようにクエリを変更するにはどうすればよいですか?
UPDATED : ベース ドキュメントのより完全なビューを提供するため。すみません、以前はありませんでした。
更新 2 ええと、私はお粗末な質問者です。データの下の値がオブジェクトではなく、オブジェクトを 1 つだけ保持する配列であるため、<< データ >> サブドキュメントが失敗します。私はそのオブジェクトの抽出を理解しようとすることについて頭を悩ませています。