Server IP : 162.213.251.212 / Your IP : 3.15.150.38 [ Web Server : LiteSpeed System : Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : allssztx ( 535) PHP Version : 8.1.31 Disable Function : NONE Domains : 1 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/home/allssztx/needapair.com/node_modules/mongodb/src/operations/ |
Upload File : |
import type { Document } from '../bson'; import type { Collection } from '../collection'; import type { Server } from '../sdam/server'; import type { ClientSession } from '../sessions'; import { decorateWithCollation, decorateWithReadConcern } from '../utils'; import { CommandOperation, type CommandOperationOptions } from './command'; import { Aspect, defineAspects } from './operation'; /** @public */ export type DistinctOptions = CommandOperationOptions; /** * Return a list of distinct values for the given key across a collection. * @internal */ export class DistinctOperation extends CommandOperation<any[]> { override options: DistinctOptions; collection: Collection; /** Field of the document to find distinct values for. */ key: string; /** The query for filtering the set of documents to which we apply the distinct filter. */ query: Document; /** * Construct a Distinct operation. * * @param collection - Collection instance. * @param key - Field of the document to find distinct values for. * @param query - The query for filtering the set of documents to which we apply the distinct filter. * @param options - Optional settings. See Collection.prototype.distinct for a list of options. */ constructor(collection: Collection, key: string, query: Document, options?: DistinctOptions) { super(collection, options); this.options = options ?? {}; this.collection = collection; this.key = key; this.query = query; } override get commandName() { return 'distinct' as const; } override async execute(server: Server, session: ClientSession | undefined): Promise<any[]> { const coll = this.collection; const key = this.key; const query = this.query; const options = this.options; // Distinct command const cmd: Document = { distinct: coll.collectionName, key: key, query: query }; // Add maxTimeMS if defined if (typeof options.maxTimeMS === 'number') { cmd.maxTimeMS = options.maxTimeMS; } // we check for undefined specifically here to allow falsy values // eslint-disable-next-line no-restricted-syntax if (typeof options.comment !== 'undefined') { cmd.comment = options.comment; } // Do we have a readConcern specified decorateWithReadConcern(cmd, coll, options); // Have we specified collation decorateWithCollation(cmd, coll, options); const result = await super.executeCommand(server, session, cmd); return this.explain ? result : result.values; } } defineAspects(DistinctOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE, Aspect.EXPLAINABLE]);