mongoose-paginate-v2
mongoose-paginate-v2 copied to clipboard
Have problem with using libary. Early some working is good. I check that 4 days ago implemented new version.
@ypicard Is this something you can help with.
@ypicard I hope that u can help me. Guys senks for u workimg!!
@aravindnc Meybe u can help with this problem?
Did you try reading the Typescript instructions ?
You seem to be using the wrong arguments to your model definition.
@ypicard import paginate from 'mongoose-paginate-v2';
// declare your schema export const institutionSchema = new Schema({ name: String });
// paginate with this plugin institutionSchema.plugin(paginate);
// declare a mongoose document based on a Typescript interface representing your schema interface InstitutionDocument extends Document, InstitutionData {}
// create the paginated model const model = mongoose.model< InstitutionDocument, PaginateModel<InstitutionDocument>
('Institutions', institutionSchema, 'institutions'); This is an example from the instructions, but it's not entirely clear where the PaginateModel comes from
The documentation can be improved indeed. Try the following:
import { PaginateModel } from 'mongoose';
Hope this is resolved. @TOLDINS
Any news @TOLDINS ? Can we close this?
I am sorry for jumpping in, I have an issue when trying to
import { PaginateModel } from 'mongoose';
Module '"mongoose"' has no exported member 'PaginateModel'. Did you mean to use 'import PaginateModel from "mongoose"' instead?
I tried to install @types/mongoose-paginate-v2 but no luck
But after install @types/mongoose-paginate or @types/[email protected] it works
Do you have any ideal on this? (I am importing from NestJS)
You should not install @types/mongoose-paginate-v2 as they are for older versions of this package. It should work out of the box by following the README instructions. Could you provide additional information on what the problem is?
Thank you so much @ypicard, I successfully to import PaginateModel the problem is I plugin library wrong way Wrong way:
connectionFactory: (connection) => {
connection.plugin(require('mongoose-paginate-v2'));
return connection;
},
So I imported like this, and it works
import * as mongoosePaginate from 'mongoose-paginate-v2';
connectionFactory: (connection) => {
connection.plugin(mongoosePaginate);
return connection;
},
Ah yes, this depends if you are using ESM or CJS syntax. Glad it worked out for you!