Skip to content

Instantly share code, notes, and snippets.

@renanccastro
Created January 6, 2022 19:23
Show Gist options
  • Save renanccastro/f0d3af3feb3567cb2ee90353c9720968 to your computer and use it in GitHub Desktop.
Save renanccastro/f0d3af3feb3567cb2ee90353c9720968 to your computer and use it in GitHub Desktop.
oplog changes mongo 5
import { oplogV2V1Converter } from './oplog_v2_converter';
Tinytest.only('oplog - v2/v1 conversion', function(test) {
const entry1 = {
$v: 2,
diff: { scustom: { sEJSON$value: { u: { EJSONtail: 'd' } } } },
};
const entry2 = {
$v: 2,
diff: { u: { d: '2', oi: 'asdas' } },
};
//set inside an array
const entry3 = { $v: 2, diff: { sasd: { a: true, u0: 2 } } };
//unset inside an array
const entry4 = { $v: 2, diff: { sasd: { a: true, u0: null } } };
//set a new nested field inside an object
const entry5 = {
$v: 2,
diff: { i: { a: { b: 2 } } },
};
//set an existing nested field inside an object
const entry6 = {
$v: 2,
diff: { sa: { i: { b: 3, c: 1 } } },
};
//unset an existing nested field inside an object
const entry7 = {
$v: 2,
diff: { sa: { d: { b: false } } },
};
test.equal(oplogV2V1Converter(entry1), {
$v: 2,
$set: { 'custom.EJSON$value.EJSONtail': 'd' },
});
test.equal(oplogV2V1Converter(entry2), {
$v: 2,
$set: { d: '2', oi: 'asdas' },
});
test.equal(oplogV2V1Converter(entry3), { $v: 2, $set: { 'asd.0': 2 } });
test.equal(oplogV2V1Converter(entry4), { $v: 2, $unset: { 'asd.0': true } });
test.equal(oplogV2V1Converter(entry5), { $v: 2, $set: { 'a.b': 2 } });
test.equal(oplogV2V1Converter(entry6), {
$v: 2,
$set: { 'a.b': 3, 'a.c': 1 },
});
test.equal(oplogV2V1Converter(entry7), { $v: 2, $unset: { 'a.b': true } });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment