Meteorite collection observes changes

Good morning. You have few problems observing the meteor collection.

I'm trying to catch the moments when my collection is changed (added record, deleted ...)

The problem is that my observable “added” function is called not only when a document is added to the collection, but when the meteor project and the meteor system are called, it adds existing records to the database. (it requires that every existing document from the collection)

Please help me configure my observer, I need to catch only changes from the user, but not from starting the system initialization. Maybe this is a way to initialize my server-side observer after initializing the meteor database?

Here is my code:

/app/collections/collections.js

groups = new Mongo.Collection('groups');

groups.allow({
    insert:function(){
        return true;
    },
    update:function(){
        return true;
    },
    remove:function(){
        return true;
    }
});

/server/observers/groups_observer.js

groups.find().observe({
added: function(document){
    console.log('groups observe added value function');
    console.log(document);
},
changed:function(new_document, old_document){
    console.log('groups observe changed value function');
},
removed:function(document){
    console.log('groups observe removed value function');
}
});
+4
1

:

  • created_at

  • created_at

doc :

groups.insert({
            created_by:Meteor.userId(),
            created_at: new Date(),
            .......
        });

,

var now = new Date();
groups.find({created_at : {$gt:now}}).observe({
    added: function(document){
        console.log('groups observe added value function');
        console.log(document);
    },
    changed:function(new_document, old_document){
        console.log('groups observe changed value function');
    },
    removed:function(document){
        console.log('groups observe removed value function');
    }
});

: cursor.observe({}) Meteor

@Francesco Pezzella )

+3

All Articles