mongoose-paginate-v2 icon indicating copy to clipboard operation
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.

Open TOLDINS opened this issue 3 years ago • 12 comments

Снимок экрана 2022-02-09 в 18 10 15 Снимок экрана 2022-02-09 в 18 10 28 Снимок экрана 2022-02-09 в 18 10 43

TOLDINS avatar Feb 09 '22 16:02 TOLDINS

@ypicard Is this something you can help with.

aravindnc avatar Feb 09 '22 18:02 aravindnc

@ypicard I hope that u can help me. Guys senks for u workimg!!

TOLDINS avatar Feb 09 '22 22:02 TOLDINS

@aravindnc Meybe u can help with this problem?

TOLDINS avatar Feb 10 '22 18:02 TOLDINS

Did you try reading the Typescript instructions ?

You seem to be using the wrong arguments to your model definition.

ypicard avatar Feb 10 '22 19:02 ypicard

@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

TOLDINS avatar Feb 11 '22 10:02 TOLDINS

The documentation can be improved indeed. Try the following:

import { PaginateModel } from 'mongoose';

ypicard avatar Feb 16 '22 06:02 ypicard

Hope this is resolved. @TOLDINS

aravindnc avatar Mar 02 '22 18:03 aravindnc

Any news @TOLDINS ? Can we close this?

ypicard avatar Mar 17 '22 18:03 ypicard

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)

fxanhkhoa avatar Jul 16 '22 13:07 fxanhkhoa

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?

ypicard avatar Jul 19 '22 07:07 ypicard

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;
},

fxanhkhoa avatar Jul 19 '22 07:07 fxanhkhoa

Ah yes, this depends if you are using ESM or CJS syntax. Glad it worked out for you!

ypicard avatar Jul 30 '22 19:07 ypicard