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

Method addQueryModifier

src/cursor/find_cursor.ts:265–321  ·  view source on GitHub ↗

* Add a query modifier to the cursor query * * @param name - The query modifier (must start with $, such as $orderby etc) * @param value - The modifier value.

(name: string, value: string | boolean | number | Document)

Source from the content-addressed store, hash-verified

263 * @param value - The modifier value.
264 */
265 addQueryModifier(name: string, value: string | boolean | number | Document): this {
266 this.throwIfInitialized();
267 if (name[0] !== '$') {
268 throw new MongoInvalidArgumentError(`${name} is not a valid query modifier`);
269 }
270
271 // Strip of the $
272 const field = name.substr(1);
273
274 // NOTE: consider some TS magic for this
275 switch (field) {
276 case 'comment':
277 this.findOptions.comment = value as string | Document;
278 break;
279
280 case 'explain':
281 this.findOptions.explain = value as boolean;
282 break;
283
284 case 'hint':
285 this.findOptions.hint = value as string | Document;
286 break;
287
288 case 'max':
289 this.findOptions.max = value as Document;
290 break;
291
292 case 'maxTimeMS':
293 this.findOptions.maxTimeMS = value as number;
294 break;
295
296 case 'min':
297 this.findOptions.min = value as Document;
298 break;
299
300 case 'orderby':
301 this.findOptions.sort = formatSort(value as string | Document);
302 break;
303
304 case 'query':
305 this.cursorFilter = value as Document;
306 break;
307
308 case 'returnKey':
309 this.findOptions.returnKey = value as boolean;
310 break;
311
312 case 'showDiskLoc':
313 this.findOptions.showRecordId = value as boolean;
314 break;
315
316 default:
317 throw new MongoInvalidArgumentError(`Invalid query modifier: ${name}`);
318 }
319
320 return this;
321 }
322

Callers 2

makeCursorFunction · 0.80
cursor.test-d.tsFile · 0.80

Calls 1

formatSortFunction · 0.90

Tested by 1

makeCursorFunction · 0.64