Javascript 可以从Meteor读取所有数据库操作吗?

Javascript 可以从Meteor读取所有数据库操作吗?,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,如果我有这样的数据库设置: @Apples = new Meteor.Collection 'apples' 是否有一种方法可以设置每次在Apple上执行数据库操作时调用的函数?例如 Apple.update {name: 'Frank'} 导致这样的事情被称为: appleOperation = (operation, parameter) -> # Log the operation in another database # Continue with the d

如果我有这样的数据库设置:

@Apples = new Meteor.Collection 'apples'
是否有一种方法可以设置每次在Apple上执行数据库操作时调用的函数?例如

Apple.update {name: 'Frank'}
导致这样的事情被称为:

appleOperation = (operation, parameter) ->
    # Log the operation in another database
    # Continue with the database operation

我相信您可能正在查找cursor.observeChanges和/或cursor.observeChanges。对不起,我没用咖啡

Apples = new Meteor.Collection("apples");

Apples.find().observe({
    added: function(document) {
        // Do stuff with the added document
    },
    changed: function(newDoc, oldDoc) {
        // Do stuff with the old and new document
    },
    removed: function(document) {
        // Do stuff with the removed document
    }
});
如果现在添加文档:

Apples.insert({name: "Frank"});
添加的函数将以插入Frank的ID和{name:“Frank”}作为fields参数进行调用

与observeChanges类似,它只提供更改的字段

Apples.find().observeChanges({
    added: function(id, fields) {
        // Do stuff with the added document
    },
    changed: function(id, fields) {
        // Do stuff with the changed fields
    },
    removed: function(id) {
        // Do stuff with the id of the removed document
    }
});

请看

是的,有一个很好的包来处理所有的细节:


这看起来像我要找的!谢谢