Is it possible to use a variable in a meteor collection update/removal?

前端 未结 3 516
粉色の甜心
粉色の甜心 2021-01-26 09:38

So I was thinking about refactoring my code in the following way.

Meteor.call(\"RemoveNotification\", this._id, function(error, response){
}

an

3条回答
  •  有刺的猬
    2021-01-26 10:00

    Yes it is possible: in javascript you need to use square bracket notation to get an object using a string variable, which means you need to work down from its parent. On the server, as elsewhere in Node.js, the global object is just global (it would be window on the client). So:

    global[collection].remove(id);
    

    should do it, provided you're referring to a valid collection (which you can check by seeing if collection in global returns true).

提交回复
热议问题