Skip to content

Instantly share code, notes, and snippets.

@vnugent
Created September 10, 2022 12:03
Show Gist options
  • Save vnugent/b9f505ec1b430253c1187d7ca3678074 to your computer and use it in GitHub Desktop.
Save vnugent/b9f505ec1b430253c1187d7ca3678074 to your computer and use it in GitHub Desktop.
case 'areas': {
if (dbOp === 'update') {
const prevId = fullDocument?._change?.prevChangeId
if (prevId != null) {
const area = await getChangeLogModel().aggregate([
{ $match: { _id: prevId } },
{
$project:
{
changes: {
$filter: {
input: '$changes',
as: 'item',
cond: { $eq: ['$$item.fullDocument._id', fullDocument._id] }
}
}
}
},
{
$unwind: '$changes'
}])
console.log('# get previous', area[0].changes.fullDocument)
console.log('# get current', fullDocument)
const diff = Diff.diffJson(area[0].changes.fullDocument.children, fullDocument.children, { ignoreWhitespace: true })
console.log('#diff', diff)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment