我有一个收藏:
{
"_id" : "SeGtBvCT7ojF2v5x9",
"teamId" : "d74JJ9s5k6tijeQaz",
"userScores" : [
{
"userId" : "6ghphqzx9GFnvKYKY",
"scores" : 10,
"addedAt" : ISODate("2019-02-04T06:37:06.387Z")
},
{
"userId" : "56ghp45hqzx9G2dda",
"scores" : 1,
"addedAt" : ISODate("2019-02-04T06:37:19.105Z")
},
{
"userId" : "wrr3422fwefx6fFGs",
"scores" : 4,
"addedAt" : ISODate("2019-02-04T06:37:44.005Z")
}
]
}
我需要为一个团队 ID 和当前用户 ID (this.userId) 返回“userScores”。所以我做了这个发布方法。
Meteor.publish('scoresTeamByUser', function(teamId) {
return Scores.find(
{ teamId },
{ userScores: { $elemMatch: { userId: this.userId } } }
);
});
但是在流星/反应应用程序中,我收到(this.props.receivedScores)整个文档,所有行都在“userScores”中。
export default withTracker(props => {
const scoresSubscription = Meteor.subscribe('scoresTeamByUser', props.teamId);
return {
receivedScores: Scores.findOne(),
scoresLoaded: scoresSubscription.ready()
};
})(GiveScores);
如何只获取一个团队和一个给出分数的用户的数据?谢谢 :)