Skip to content

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).

Parameter Type
fields MongoKeysetFields

MongoKeyset

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);