我有documents
games
集合。每个文档负责保存运行游戏所需的数据。这是我的文档结构返回数组元素的特定属性 - MongoDB /流星
{
_id: 'xxx',
players: [
user:{} // Meteor.users object
hand:[] //array
scores:[]
calls:[]
],
table:[],
status: 'some string'
}
基本上这是我的纸牌游戏(电话桥)的结构。现在我想要发布的是,玩家将在他的浏览器(minimongo)中有他的hand
数据以及其他玩家user, scores, calls
字段。所以下载到浏览器的订阅将是这样的。
{
_id: 'xxx',
players: [
{
user:{} // Meteor.users object
hand:[] //array
scores:[]
calls:[]
},
{
user:{} // Meteor.users object
scores:[]
calls:[]
},
// 2 more player's data, similar to 2nd player's data
],
table:[],
status: 'some string'
}
players.user
对象具有_id
属性,该属性区分用户。在流星发布方法中,我们可以访问this.userId
,它返回正在请求数据的userId。这意味着我想要_id
与this.userId
匹配的那个用户的嵌套hand
数组。我希望这些解释能帮助你写出更准确的解决方案。
我不认为聚合会适用于我的情况。我需要返回一个查找光标流星发布 –