toMongoKeyset
function toMongoKeyset(fields): MongoKeyset;Defined in: pagination-mongo.ts:97
Create a MongoDB/Mongoose adapter for portable keyset predicates and sorting.
The adapter emits plain filter/sort objects suitable for MongoDB driver and
Mongoose APIs: Model.find(filter).sort(sort).limit(limit).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fields |
MongoKeysetFields |
Returns
Section titled “Returns”Example
Section titled “Example”import { toMongoKeyset } from "@xtandard/lib/pagination/mongo";
const mongoKeyset = toMongoKeyset({ createdAt: "createdAt", id: "_id",});
const items = await Post .find(mongoKeyset.filter(keyset.where(cursor, direction)) ?? {}) .sort(mongoKeyset.sort(keyset.orderBy(direction))) .limit(limit);