@conpago/mongo-cursor-pagination
Version:
Make it easy to return cursor-paginated results from a Mongo collection
23 lines (22 loc) • 1.33 kB
TypeScript
import { Collection } from "mongodb";
import { PaginationResponse, SearchParams } from "./types";
/**
* Performs a search query on a Mongo collection and pages the results. This is different from
* find() in that the results are ordered by their relevancy, and as such, it does not take
* a paginatedField parameter. Note that this is less performant than find() because it must
* perform the full search on each call to this function.
*
* @param {Collection} collection A collection object returned from the MongoDB library's. This MUST have a Mongo
* $text index on it.
* See https://docs.mongodb.com/manual/core/index-text/.
* @param {String} searchString String to search on.
* @param {QueryParams} params
* @param {object} params.query The find query.
* @param {Number} params.limit The page size. Must be between 1 and `config.MAX_LIMIT`.
* @param {object} params.fields Fields to query in the Mongo object format, e.g. {title :1}.
* The default is to query ONLY _id (note this is a difference from `find()`).
* @param {String} params.next The value to start querying the page. Defaults to start at the beginning of
* the results.
*/
declare const _default: (collection: Collection | any, searchString: string, params: SearchParams) => Promise<PaginationResponse>;
export default _default;