/
1Rrd0
/
Course
Обзор
Документация
Войти
/
1Rrd0
/
Course
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
node_modules/mongoose/lib/helpers/update/decorateUpdateWithVersionKey.js
35 строк
799 B
dima
2
13 дек 2025, 10:58
13 дек 2025, 10:58
ce5a48e
Код
Авторство
О чём код?
'use strict'; /** * Decorate the update with a version key, if necessary * @api private */ module.exports = function decorateUpdateWithVersionKey(update, options, versionKey) { if (!versionKey || !(options && options.upsert || false)) { return; } if (options.overwrite) { if (!hasKey(update, versionKey)) { update[versionKey] = 0; } } else if ( !hasKey(update, versionKey) && !hasKey(update?.$set, versionKey) && !hasKey(update?.$inc, versionKey) && !hasKey(update?.$setOnInsert, versionKey) ) { if (!update.$setOnInsert) { update.$setOnInsert = {}; } update.$setOnInsert[versionKey] = 0; } }; function hasKey(obj, key) { if (obj == null || typeof obj !== 'object') { return false; } return Object.hasOwn(obj, key); }