MCPcopy
hub / github.com/mongodb/node-mongodb-native / makeUpdateStatement

Function makeUpdateStatement

src/operations/update.ts:253–292  ·  view source on GitHub ↗
(
  filter: Document,
  update: Document | Document[],
  options: UpdateOptions & { multi?: boolean } & { sort?: Sort }
)

Source from the content-addressed store, hash-verified

251}
252
253export function makeUpdateStatement(
254 filter: Document,
255 update: Document | Document[],
256 options: UpdateOptions & { multi?: boolean } & { sort?: Sort }
257): UpdateStatement {
258 if (filter == null || typeof filter !== 'object') {
259 throw new MongoInvalidArgumentError('Selector must be a valid JavaScript object');
260 }
261
262 if (update == null || typeof update !== 'object') {
263 throw new MongoInvalidArgumentError('Document must be a valid JavaScript object');
264 }
265
266 const op: UpdateStatement = { q: filter, u: update };
267 if (typeof options.upsert === 'boolean') {
268 op.upsert = options.upsert;
269 }
270
271 if (options.multi) {
272 op.multi = options.multi;
273 }
274
275 if (options.hint) {
276 op.hint = options.hint;
277 }
278
279 if (options.arrayFilters) {
280 op.arrayFilters = options.arrayFilters;
281 }
282
283 if (options.collation) {
284 op.collation = options.collation;
285 }
286
287 if (!options.multi && options.sort != null) {
288 op.sort = formatSort(options.sort);
289 }
290
291 return op;
292}
293
294defineAspects(UpdateOperation, [
295 Aspect.RETRYABLE,

Callers 7

updateMethod · 0.90
updateOneMethod · 0.90
replaceOneMethod · 0.90
rawFunction · 0.90
constructorMethod · 0.85
constructorMethod · 0.85
constructorMethod · 0.85

Calls 1

formatSortFunction · 0.90

Tested by

no test coverage detected