如何根据我公司数据库中的字段在启动时创建多个馆藏?集合?
目前我在客户端和服务器上:
datacollections = {};
CompanyData = new Meteor.Collection('companydata');
Meteor.startup(function(){
DataCollectionList = CompanyData.find({},{fields: {'data':1}});
DataCollectionList.forEach(function(doc){
datacollections[doc.data] = new Meteor.Collection(doc.data);
console.log(datacollections[doc.data].findOne())
})
});
这在服务器端工作,因为服务器控制台在启动时打印数据对象。但是,客户端只打印undefined。如何在客户端上获取此数据?
答案 0 :(得分:0)
Try this:
datacollections = {};
CompanyData = new Meteor.Collection('companydata');
Meteor.startup(function(){
DataCollectionList = CompanyData.find({},{fields: {'data':1}});
DataCollectionList.forEach(function(doc){
datacollections[doc.data] = new Meteor.Collection(doc.data);
//-----------------------------------------------------
Meteor.publish(null ,function() {
// null name means send to all clients.
return datacollections[doc.data];
});
//-----------------------------------------------------
console.log(datacollections[doc.data].findOne())
})
});