@sotatech/query3
Version:
A flexible query handler for MongoDB using Mongoose
57 lines • 2.25 kB
TypeScript
import { Model, PipelineStage } from 'mongoose';
import { Query3Options, PaginationResult } from './query3.type';
/**
* Query3 - A flexible query handler for MongoDB models.
* Supports advanced filtering, pagination, operator validation, and aggregation pipelines.
*/
export declare class Query3<T = any> {
private model;
/**
* @param model - The MongoDB model to be queried.
*/
constructor(model: Model<T>);
/**
* Validates if the operators in the query are allowed.
* Throws an error if an operator is not part of the allowed list.
*
* @param query - The parsed query object.
* @param allowedOperators - The list of operators allowed for this query.
*/
private validateOperators;
/**
* Parses the query string into a structured MongoDB query object.
*
* @param queryString - The query string from the client (e.g., "?limit=10&offset=0").
* @param options - Additional options for the query.
* @returns A structured MongoDB query object with filters, limits, offsets, etc.
*/
private parseQueryString;
/**
* Executes a query based on the provided query string and options.
* Supports filtering, pagination, field omission, and population.
*
* @param queryString - The query string from the client (e.g., "?limit=10&offset=0").
* @param options - Additional query options, such as populate, omitFields, and custom filters.
* @returns The query results and pagination metadata.
*/
query(queryString: string, options?: Query3Options<T>): Promise<{
records: T[];
pagination: PaginationResult;
}>;
/**
* Removes specified fields from the result set.
*
* @param data - The array of records to process.
* @param fields - The list of fields to remove from each record.
* @returns The processed array of records with specified fields removed.
*/
private omitFields;
/**
* Executes an aggregation pipeline on the model.
*
* @param pipeline - The aggregation pipeline stages.
* @returns The result of the aggregation pipeline.
*/
aggregate(pipeline: PipelineStage[]): Promise<any[]>;
}
//# sourceMappingURL=query3.d.ts.map