MongoDBのクエリ/集計が必要:配列がある場合、配列の異なる値に応じてドキュメントをグループ化するにはどうすればよいですか?例:アレイ内の異なるオブジェクトの値はグループ化されていますか?
私は、これらのオブジェクトがある場合:
> db.respondents.insert({person: 1, responses: [{question: 'How old are you?', response: '18-40 yrs'}, {question: 'What is the brand of your car?', response: 'Fiat'} ] })
> db.respondents.insert({person: 2, responses: [{question: 'How old are you?', response: '18-40 yrs'}, {question: 'What is the brand of your car?', response: 'Volvo'} ] })
> db.respondents.insert({person: 3, responses: [{question: 'How old are you?', response: '41-65 yrs'}, {question: 'What is the brand of your car?', response: 'Volvo'} ] })
> db.respondents.insert({person: 4, responses: [{question: 'How old are you?', response: '41-65 yrs'}, {question: 'What is the brand of your car?', response: 'Volvo'} ] })
をそして、何の車のブランドの回答者の年齢グループ(別名内訳の質問)あたり自身(別名ベースの質問に)私に語ったクエリを記述したいと思いますか?
だから、答えは私に教えてください:
1人の年齢層'18 -40' あなたの車のブランドは何ですか 『質問する『フィアットを答え』』?年齢層'18でが
1人が-40' ボルボはあなたの車のブランドは何ですか 『疑問を『答え』?』
'41 -65 'の年齢層の2人が'あなたの車のブランドは何ですか?
そしてIRL:
- 100.000+回答
- がある回答者あたり約30 'の応答は'
- ありMongoDBの3.0.9
を使用している私が試してみました数多くの方法がありますが、私の失敗であなたを退屈させません....
私はここでSOのコメントのガイドラインを無視して書いています:+1、ありがとう - あなたは私のヒーローです!甘味。まさに私が達成しようとしていたもの。 –
すみません、もちろん「ヒロイン」を意味します。私はそれが昨日の月明かりではないと確信しました。 –