Dynamic Collection Implementation


#1

I am creating dynamic collection in my application but I am not able to fetch, insert and update that dynamic collection.

Dynamic collection created when I am inserting a Record in different collection
for example I have person collection and want to create dynamic collection of task to dynamically separate task collection of every person .

Please help me out how can I implement the same in meteor ?


#2

How are you trying to do this in your code base?

(can we see some code?)


#3

var collectionCache = {};
function create_collection(name) {
collectionCache[name] = new Mongo.Collection(name);

Meteor.publish(collectionCache[name], function() {
return global[collectionCache[name]].find();
});

}

my collection name is task_parentID

now data should saved in task_parentID where parentID is unique ID of that parent


#4

Since you are publishing from these collections, they also need to be set up on the client. That means that your code needs to run on the client and the server, with only the publications on the server (and presumably, matching subscriptions on the client). So maybe something like the following?

var collectionCache = {};
function create_collection(name) {
  collectionCache[name] = new Mongo.Collection(name);
  if (Meteor.isServer) {
    Meteor.publish(collectionCache[name], function() {
      return global[collectionCache[name]].find(); // Don't see where collectionCache gets added to global
    });
  }
}