Files
wekan/models/lib/exactFieldSelector.js
T
Lauri Ojansivu 0d2dd1d36e Prepare conditional field patches for durable Sync steps
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.
2026-09-28 01:59:40 +03:00

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 };