0
私は使用された単語のリストと全体のスコアのリストを返しません。モンゴー集約で2つの配列を返そうとしています
私はこの
"negativeWords" : [
"Angry"
],
"positiveWords" : [
"Happy"
],
のように私のdoc内の各ドキュメントは、複数の正または負の言葉を持つことができています。 、[4:各ドキュメントのために
words : [Angry, Happy, Sad, bad, excited]
、全体的なスコアの配列:
全体の
"overall" : 3,
は、私のような配列を取得したい:
も各ドキュメントのような全体的なスコアを持っています3,2,5、]
私は両方を取得する方法がわかりません。
Review.aggregate([
//now I want to get the overall scores and the array of words
{
$project: {
arr : {"$setUnion" : ["$negativeWords", "$positiveWords"]},
overallScores : "$overall"
}
},
{
$unwind : "$arr"
},
{
$group : {
_id : "$_id",
words : {$push : "$arr"},
overallScores : {$first : "$overallScores"}
}
},
EDIT: 出力にはここまでです。私は配列を取得したい:
[ { _id: 5898b02c1321831b84740320,
words: [ 'Angry', 'Happy' ],
overallScores: 3 },
{ _id: 5898b02c1321831b8474031f,
words:
[ 'Difficult',
'Easy returns',
'Afordable',
'Great products',
'Good service' ],
overallScores: 5 },
{ _id: 5898b02c1321831b8474031e,
words:
[ 'Difficult',
'Easy returns',
'Afordable',
'Great products',
'Good service' ],
overallScores: 5 },
{ _id: 5898b02c1321831b8474031d,
words: [ 'Caring', 'Easy returns', 'Bad', 'Expensive' ],
overallScores: 3 },
{ _id: 5898b02c1321831b8474031c,
words: [ 'Difficult', 'Afordable', 'Awesome' ],
overallScores: 4 },
{ _id: 5898b02c1321831b8474031b,
words: [ 'Bad', 'Respect', 'Rude', 'Expensive', 'Disgusted' ],
overallScores: 3 },
{ _id: 5898b02c1321831b8474031a,
words: [ 'Difficult', 'Afordable' ],
overallScores: 4 },
{ _id: 5898b02c1321831b84740319,
words: [ 'No refund', 'Respect' ],
overallScores: 3 } ]
コード:ここで
{
$project: {
arr : {"$setUnion" : ["$negativeWords", "$positiveWords"]},
overallScores : "$overall"
}
},
{
$unwind : "$arr"
},
{$unwind : "$overallScores"},
{
$group : {
_id : "$_id",
words : {$push : "$arr"},
overallScores : {$first : "$overallScores"}
}
}
全体のフィールドはに関連しない方法配列、またはそれらはありませんか? –
全体は単なる数字です。彼らは、肯定的な単語と否定的な単語の配列には関係しません。 –