mongoid-history icon indicating copy to clipboard operation
mongoid-history copied to clipboard

Auditing BulkWrite in MogoDB

Open renegadeHomie opened this issue 8 years ago • 3 comments

Hi, I successfully implemented this gem for document create, update and destroy.

But I am doing a Bulk Write operation in my program and the history tracker is not able to track those changes.

Does mongoid-history support Bulk Write? If yes, how should it be implemented and if no what can be done to make it track all Bulk write operations.

Thanks

renegadeHomie avatar Feb 15 '17 10:02 renegadeHomie

How do you do a bulk insert? If it's via collection.insert, you're effectively bypassing Mongoid and going to the MongoDB ruby driver, so there're no callbacks as far as I know.

dblock avatar Feb 15 '17 12:02 dblock

bulk = Mongo::BulkWrite.new(ModelName.collection, insertdata, ordered: false) bulk.execute I am using the above query, where insertdata is an array containing data to be written! I am using Mongo::BulkWrite as you can see.

renegadeHomie avatar Feb 15 '17 17:02 renegadeHomie

Oh that's new, I've never used it. I think for a bulk write we'd want a bulk history update, so some kind of extension that goes over documents, figures out the tracked data, appends it to insertdata, then bulk inserts it.

dblock avatar Feb 15 '17 18:02 dblock