【发布时间】:2015-08-25 01:31:45
【问题描述】:
我正在尝试构建一个在 Meteor 中具有多对多关系的应用程序。将有工作、客户和用户集合。客户可以有多个工作,最重要的是多个用户可以从事同一个工作。
我在我的fixtures 文件中按如下方式设置了jobs 集合:
Jobs.insert({
jobNum: 'Somejob',
clientId: 'XXXXXXXX',
clientName: 'Some Client',
rate: XX,
userNames: [
{userId: user1._id},
{userId: user2._id}
],
active: true
});
我正在根据发布复合的自述文件发布,但我无法让用户发布到客户端。这是发布代码:
Meteor.publishComposite('jobsActive', {
find: function() {
// Find all active jobs any client
return Jobs.find({active: true});
},
children: [
{
find: function (job) {
// Return a client associated with the job
return Clients.find({_id: job.clientId});
}
},
{
find: function (job) {
// Return all users associated with the job
// This is where the problem is
return Meteor.users.find({_id: job.userNames.userId});
}
}
]
});
我不知道如何正确查找数组。我尝试了很多东西,但没有任何效果。这可能吗?还是我需要以其他方式解决这个问题?我考虑过在 users 集合中引用作业,但是作业会比用户多得多,所以这样似乎更有意义。
顺便说一句,我也订阅了“jobsActive”。其他两个集合很好地来到客户端;我只是无法让用户集合发布。
感谢任何帮助和想法。
【问题讨论】:
标签: javascript mongodb meteor mongodb-query