简体   繁体   中英

MongoDB track which user mande changes

We're running a microservice architecture with multiple systems having access to shared collections in a MongoDB (yes, questionable design, but we're in the transition to get out of this.)

We're trying to find a way to track which change within the oplog was done by which "user"/service (each microservice is using different credentials) actually made this change. If we find any invalid changes in our DB this would make it super easy to find out which system is bugging out.

Any ideas?

The only ones I came up with so far would always have to change client side code, which I would like to avoid.

If you can maintain a column editors such that every operation would have an { $addToSet: { editors: { by: userId, at: new Date() } } } , then the corresponding oplog entries would have this information that you can cross-check with your access control list.

Note: you might have to change inserts to upserts, or account for another case: .insert({ ..., editors: [{ by: userId, at: new Date() }] })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM