如何监听所有mongoDB集合中的更改

时间:2016-04-06 18:20:53

标签: meteor

我正在写一个流星应用, 我想写一个观察者,它将听取远程mongoDB的变化, 虽然我想写一些通用的,它会听取所有收藏品并发送旧值和新值。我的意思是:

var DBCollections = new Meteor.Collection.getall();  -> whats the right way to do this?

var cursor = DBCollection.find();


// watch the cursor for changes
var handle = cursor.observe({
  added: function (object) {
    var result = Meteor.http.post(
       "http://localhost:8080",
       { params: { command: "add_object", value: object} } );


   },
  changed: function (object) {
    oldValue = ???   -> how can I get it?
     var result = Meteor.http.post(
    "http://localhost:8080",
        { params: {command:"modify_object",oldValue: oldValue,newValue: object}} );


       },
  removed: function (object) {
      var result = Meteor.http.post(
     "http://localhost:8080",
     { params: { command: "remove_object",value: object } } );

   }
}); 

所以我的问题是这样的:

  1. 如何获取所有馆藏并观察其变化?

  2. 修改对象后如何获取旧值?

0 个答案:

没有答案