Reputation: 2943
i'm quite new to deno and mongodb. I'm trying to skip document for pagination.
Here's the code:
let { page } = Object.fromEntries(request.url.searchParams);
page = parseInt(page);
console.log(page);
console.log(typeof page);
let res = await users.find().skip((page - 1) * 10).limit(10);
console.log(res);
Here's the error i get:
2
number
TypeError: users.find(...).skip is not a function
at userLoad (file:///C:/Users/shoti/OneDrive/Desktop/drreglog/router.js:42:34)
at dispatch (https://deno.land/x/oak/middleware.ts:35:32)
at https://deno.land/x/oak/router.ts:416:18
at dispatch (https://deno.land/x/oak/middleware.ts:35:32)
at composedMiddleware (https://deno.land/x/oak/middleware.ts:41:12)
at dispatch (https://deno.land/x/oak/router.ts:420:28)
at dispatch (https://deno.land/x/oak/middleware.ts:35:32)
at Object.composedMiddleware [as middleware] (https://deno.land/x/oak/middleware.ts:41:12)
at Application.#handleRequest (https://deno.land/x/oak/application.ts:190:21)
Upvotes: 2
Views: 90
Reputation: 5245
I assume you are using mongo
module
From the source code, skip
and limit
should be passed as options
argument
let res = await users.find({}, { skip: (page - 1) * 10, limit: 10 })
Upvotes: 1
Reputation: 5874
Could you please change the code as follows and see whether it fixes the issue?
let res = await users.find({}).skip((page - 1) * 10).limit(10);
Upvotes: 1