How to store user activities like login, insert, update ... data?


#1

I would like to store or record the users activities like when login, logout or insert, updates, remove data with datetime, docs info, user id fields …


#2

You could use collection-hooks for this ( https://github.com/matb33/meteor-collection-hooks )
You could then create a function that takes a collection as argument and automatically binds the correct hooks to the collection.
So you could have something

var Foo = new Mongo.Collection(“foo”);
watchActions(Foo);

This package does something similar to partition collections: https://github.com/mizzao/meteor-partitioner


#3

Thanks, look great for the collection hook package, but I don’t understand how to record action. It mean that I should store info in mongo collection? ???


#4

Well, you can attach hooks/listeners before and/or after any insert/update/remove/read from a collection. So in such a hook you can log that action to your mongodb, log file or other system of your choice.

For performance reasons I wouldn’t save it to your mongodb of meteor, as it will add data to the oplog, which meteor has to process but which you probably don’t expose in any publication (I assume)


#5

what the oplog?
please explain…


#6

Meteor hooks into the mongodb oplog (operation log to keep mongodb instances synchronized) in order to receive updates form the db to act upon.
Everything that will get inserted into the mongodb instance used by meteor will be added to the oplog and therefore processed by meteor (to see if it matches any publication). If you have data that is never going to be exposed by a meteor publication, it might be better (performance-wise) to store that in a separate database.


#7

Thanks, but I don’t understand and I will try store on collection of mongodb.


#8

But where do you want to store this info if not into mongodb?


#9

This kind of auditing would be very valuable (especially to track changes to the collections) for security purposes.

Perhaps the collections packages should have meta collection to auto-magically take care of these (security audits)


#10

Oh, look great if have this package (security audits).


#11

“But where do you want to store this info if not into mongodb?” – vicusbass

How about Redis? Then periodically dump into MongoDB for persistence.

p.s. Hope you don’t mind me resurrecting this question, but have similar concerns in mind.

Maybe this can be interesting: https://www.compose.io/articles/redis-mongodb-and-the-power-of-incremency/


#12

I would use (something like) Mixpanel. Also look at Telescope/packages/telescope-events on the devel branch. Hope @sacha might release such packages to Atmoshere in the future :wink:


#13

Actually I spec’d out a generic version of that package here, and @dburles also contributed some code: https://github.com/TelescopeJS/meteor-events

It’s not published to Atmosphere or used inside Telescope yet though.