Ceyhun Tekin Ceyhun Tekin - 7 months ago 31
Node.js Question

How to apply function for all Collection

I want to update my collection in

by using a function.
When I change one field I need to change multiple collections.
My question is how can I use a parameter as a Collection name. Is there any way for it or I must write a function for each Collection?

update: function(personID,option) {
return Personel.update(
{ id: personID },
{ $set: option },
{ multi: true }

I want to apply this logic for separate collections.


There is a trickier workaround for this problem. you need to actually bind all of your collection in a single object.

CollectionList = {};

CollectionList.Personel = new Mongo.Collection('personel');
CollectionList.secondCollection = new Mongo.Collection('second');

after that you pass as your collection name as a string into the method.

update: function(collectionName,personID,option){
     return CollectionList[collectionName].update(
             //..rest of your code