I’m building a wiki with versioning system similar to Wikipedia and GitHub, based on Change streams.
Depending on the user action, it may result of one or more changes to a single or multiple _history
collections. (we’re implement something like Type 4 of the Slowly Changing Dimension pattern).
I’m planning to create an audit_logs
collection to keep track changes as a unit (analogous to a git merge request). In each document, there’s an array of one or more change event documents.
In the example below, if someone adds a new user to the system, it results in a change in the profile
and the account
collection, both of which have different schemas.
Is it a common practice to embed documents with different schemas in an array?
audit_logs collection
[
{
editedBy: new Binary(Buffer.from("a927c2893cc64963b67f560c81a5dffa", "hex"), 4),
operation: 'addNewUser',
_id: new ObjectId("62dd9815b11c3e3e3d01a41c"),
createdAt: 2022-07-24T19:05:57.855Z,
changes: [
{
// 'profile' fullDocument captured by event stream
},
{
// 'account' fullDocument captured by event stream
}
]
}
...
]
Initially, I tracked changes to profile
and account
in 2 separate _history
collections but joining 3 collections with lookup
is getting a bit out of hand or if we want to rollback a change.