所以我有两个集合,Trait 和 Question。对于给定的用户,我遍历用户的特征,并且我想查询与缺失特征相对应的所有问题:
linq.From(missingTraits)
.ForEach(function(trait)
{
match.$or.push({ "Trait": trait });
});
database.collection("Questions", function(err, collection)
{
collection.find(match).limit(2).toArray(function(err, questions)
{
next(err, questions);
});
});
这可行,但我希望对象按 Trait 文档上的字段排序(不在 Question 文档中):
Traits
[
{ "Name": "Height", "Value": "73", "Importance": 15 },
{ "Name": "Weight", "Value": "230" "Importance": 10 },
{ "Name": "Age", "Value": "29", "Importance": 20 }
]
Questions
[
{ "Trait": "Height", "Text": "How tall are you?" },
{ "Trait": "Weight", "Text": "How much do you weight?" },
{ "Trait": "Age", "Text": "How old are you?" }
]
所以在上面的例子中,如果所有三个特征都缺失,我只想带回年龄和身高(按此顺序)。是否可以以某种方式修改查询或匹配对象以促进这一点?
谢谢你。