Meteor/Mongodb-阵列、子文档和;重叠订阅
我在做游戏;球员组成联盟,做出竞争性的预测。联盟是这样的:Meteor/Mongodb-阵列、子文档和;重叠订阅,mongodb,meteor,publish-subscribe,subdocument,minimongo,Mongodb,Meteor,Publish Subscribe,Subdocument,Minimongo,我在做游戏;球员组成联盟,做出竞争性的预测。联盟是这样的: {联赛名称:“英超联赛”, 玩家:[ {name:“Goodie”,secretPrediction:“abc”}, {姓名:“坏蛋”,秘书长:“def”} ] } 对于每个球员,我需要向客户发布联盟中所有球员的名字,但是只能发布他们自己的秘密预测。因此,从上面看,如果Goodie登录,mini mongo上的文档应该是: {联赛名称:“英超联赛”, 玩家:[ {name:“Goodie”,secretPrediction:“abc”
{联赛名称:“英超联赛”,
玩家:[
{name:“Goodie”,secretPrediction:“abc”},
{姓名:“坏蛋”,秘书长:“def”}
] }
对于每个球员,我需要向客户发布联盟中所有球员的名字,但是只能发布他们自己的秘密预测。因此,从上面看,如果Goodie登录,mini mongo上的文档应该是:
{联赛名称:“英超联赛”,
玩家:[
{name:“Goodie”,secretPrediction:“abc”},
{名字:“坏蛋”}
] }
为此,我有两份出版物——一份是获取整个联盟文档,但不包括所有秘密预测,另一份是获取玩家数组中当前玩家的子文档,包括她的秘密预测。我的出版物是:
//发布不包括secretPrediction的整个players数组
Leagues.find({“players.name”:“Goodie”},{fields:{“players.secretPrediction”:0})
//在玩家数组中发布整个Goodie项目,而不发布其他内容
Leagues.find({“players.name”:“Goodie”},{fields:{players:{$elemMatch:{name:“Goodie”}}})
问题是,当我订阅上述两种出版物时,我没有得到我想要的文档-即使第二种出版物也不包括秘密预测。(就其本身而言,出版物的行为与预期一致,只有在我同时订阅这两种出版物时才如此。)
现在,我从中了解到,这两个出版物应该在客户端上“合并”
至于顶级字段的级别,Meteor负责在文档之间执行集合合并,以便订阅可以重叠-发布功能将不同的顶级字段并排发送到客户端,在客户端,集合中的文档将是两组字段的合并
因此,我有两个主要问题(做得好/谢谢你这么做!):
您是否可以重新排列数据文档,以便使用单个查询,例如
{ leagueName: "Premier League",
players:[
{name: "Goodie"},
{name: "Baddie"}
]
playerPredictions:[
{name: "Goodie", secretPrediction: "abc"},
{name: "Baddie", secretPrediction: "def"}
]
}
这样,在一个查询中就可以返回所有玩家,并且只返回给定人物的playerPrediction。您是否可以重新排列数据文档,以便使用单个查询,例如
{ leagueName: "Premier League",
players:[
{name: "Goodie"},
{name: "Baddie"}
]
playerPredictions:[
{name: "Goodie", secretPrediction: "abc"},
{name: "Baddie", secretPrediction: "def"}
]
}
这样,在一个查询中就可以返回所有玩家,并且只返回给定人员的playerPrediction
[{
_id: 'league1',
name: 'League 1',
// ...
}]
[{
_id: 'player1',
name: 'Player 1',
// ...
}]
[{
_id: 'league1palyer1',
playerId: 'player1',
leagueId: 'league1',
secretPrediction: 'abc',
// ...
}]
播放器收藏:
[{
_id: 'league1',
name: 'League 1',
// ...
}]
[{
_id: 'player1',
name: 'Player 1',
// ...
}]
[{
_id: 'league1palyer1',
playerId: 'player1',
leagueId: 'league1',
secretPrediction: 'abc',
// ...
}]
League2Player系列:
[{
_id: 'league1',
name: 'League 1',
// ...
}]
[{
_id: 'player1',
name: 'Player 1',
// ...
}]
[{
_id: 'league1palyer1',
playerId: 'player1',
leagueId: 'league1',
secretPrediction: 'abc',
// ...
}]
[{
_id: 'league1',
name: 'League 1',
// ...
}]
[{
_id: 'player1',
name: 'Player 1',
// ...
}]
[{
_id: 'league1palyer1',
playerId: 'player1',
leagueId: 'league1',
secretPrediction: 'abc',
// ...
}]
播放器收藏:
[{
_id: 'league1',
name: 'League 1',
// ...
}]
[{
_id: 'player1',
name: 'Player 1',
// ...
}]
[{
_id: 'league1palyer1',
playerId: 'player1',
leagueId: 'league1',
secretPrediction: 'abc',
// ...
}]
League2Player系列:
[{
_id: 'league1',
name: 'League 1',
// ...
}]
[{
_id: 'player1',
name: 'Player 1',
// ...
}]
[{
_id: 'league1palyer1',
playerId: 'player1',
leagueId: 'league1',
secretPrediction: 'abc',
// ...
}]
1.对的2.您可以尝试仅向客户端发布“虚拟”集合。1。对的2.你可以尝试只向客户发布“虚拟”收藏。接受此作为答案,因为我认为这是获得所需结果的最简单和最快捷的方法。接受此作为答案,因为我认为这是获得所需结果的最简单和最快捷的方法。我在文档中没有看到此评论。“我们希望在未来的版本中取消这一限制。”-希望很快…文档中的好位置-我没有看到这样的评论。“我们希望在未来的版本中取消这一限制。”-希望很快。。。