sakshi
sakshi

Reputation: 171

Meteor Dynamic Collection Implementation

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 data of every person.

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

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.

Upvotes: 0

Views: 335

Answers (1)

Ankit
Ankit

Reputation: 1128

Just to confirm the problem- You want a document to be created in Task collection when a collection to be created for that Person?

I will advice against thie approach and will recommend you follow this

To explain: Create two collections - Tasks and Persons.

The document inserted in Persons will have a unique id. The Task can have a structure like this:

{ _id : //unique ID
//other fields
assignedTo: //_id of the Person to whom the task is assigned
}

The assignedTo will contain the _id of document in the Persons collection.

When you need to sort, just call the subscription as Tasks.find({assignedTo: _persons_Id}); and you will get all the tasks under the said person.

Upvotes: 0

Related Questions