我正在我的应用程序中创建动态集合,但我无法获取,插入和更新该动态集合。
我在不同集合中插入记录时创建的动态集合。 例如,我有人物收集,并希望创建动态的任务集合,以动态分离每个人的任务数据。
请帮助我如何在流星中实现相同的功能?
var collectionCache = {};
function create_collection(name) {
collectionCache[name] = new Mongo.Collection(name);
Meteor.publish(collectionCache[name], function() {
return global[collectionCache[name]].find();
});
}
我的收藏名称为task_parentID
。
现在数据应该保存在task_parentID
中,其中parentID
是该父级的唯一ID。
答案 0 :(得分:0)
只是为了确认问题 - 您希望在为Task
创建集合时在Person
集合中创建文档?
我会建议反对这种方法,并会建议您按照this
解释:
创建两个集合 - Tasks
和Persons
。
Persons
中插入的文档将具有唯一ID。 Task
可以有这样的结构:
{ _id : //unique ID
//other fields
assignedTo: //_id of the Person to whom the task is assigned
}
assignedTo
将包含_id
集合中的Persons
文档。
当您需要排序时,只需将订阅称为Tasks.find({assignedTo: _persons_Id});
,即可获得该人员下的所有任务。