【发布时间】:2016-06-24 12:25:00
【问题描述】:
我在games 集合中有documents。每个文档负责保存运行游戏所需的数据。这是我的文档结构
{
_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,它返回请求数据的用户ID。这意味着我想要_id与this.userId匹配的那个用户的嵌套hand数组。我希望这些解释可以帮助您编写更准确的解决方案。
【问题讨论】:
标签: mongodb meteor mongodb-query meteor-publications