mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Compare before/after field unions without replacing unrelated metadata. Share literal snapshot predicates with production Sync, isolate result verification from driver mutation, and reject array shapes that cannot survive BSON storage. Thanks to xet7.
15 lines
548 B
JavaScript
15 lines
548 B
JavaScript
'use strict';
|
|
// Mongo's bare null also matches missing fields, and a bare object can be
|
|
// interpreted as query operators. Snapshot values are data, never selectors.
|
|
function exactFieldSelector(snapshot, fields) {
|
|
const selector = {};
|
|
for (const field of fields) {
|
|
const value = snapshot[field];
|
|
selector[field] = value === undefined ? { $exists: false }
|
|
: value === null ? { $eq: null, $exists: true }
|
|
: typeof value === 'object' ? { $eq: value } : value;
|
|
}
|
|
return selector;
|
|
}
|
|
module.exports = { exactFieldSelector };
|