(
filter: Document,
update: Document | Document[],
options: UpdateOptions & { multi?: boolean } & { sort?: Sort }
)
| 251 | } |
| 252 | |
| 253 | export 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 | |
| 294 | defineAspects(UpdateOperation, [ |
| 295 | Aspect.RETRYABLE, |
no test coverage detected