From 80f3e721ac6415358d03fb565743aaafd607f88e Mon Sep 17 00:00:00 2001 From: Dmitry Kirilyuk Date: Wed, 23 Sep 2015 11:48:48 +0300 Subject: [PATCH] Use MyModel instead of MySchema --- README.md | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 51bc6bb..2811451 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,19 @@ npm install -S mongoose-paginate This plugin must first be added to a schema: ```js +var mongoose = require('mongoose'); var mongoosePaginate = require('mongoose-paginate'); -MySchema.plugin(mongoosePaginate); +var mySchema = new mongoose.Schema({ /**/ }); + +mySchema.plugin(mongoosePaginate); + +var MyModel = mongoose.model('MyModel', mySchema); ``` -`MySchema` will have a new function called `paginate` (e.g. `MySchema.paginate()`). +`MyModel` will have a new function called `paginate` (e.g. `MyModel.paginate()`). -### MySchema.paginate(query, options, [callback]) +### MyModel.paginate(query, options, [callback]) **Arguments** @@ -56,30 +61,30 @@ MySchema.plugin(mongoosePaginate); ```js // basic example usage of `mongoose-pagination` -// querying for `all` {} items in `MySchema` +// querying for `all` {} items in `MyModel` // paginating by second page, 10 items per page (10 results, page 2) var mongoosePaginate = require('mongoose-paginate'); -MySchema.plugin(mongoosePaginate); +mySchema.plugin(mongoosePaginate); -MySchema.paginate({}, { +MyModel.paginate({}, { page: 2, limit: 10 }, callback); ``` ```js // basic example usage of `mongoose-pagination` with promises -// querying for `all` {} items in `MySchema` +// querying for `all` {} items in `MyModel` // paginating by second page, 10 items per page (10 results, page 2) var mongoose = require('mongoose'); // required mongoose v4.1.0 or higher mongoose.Promise = require('bluebird'); var mongoosePaginate = require('mongoose-paginate'); -MySchema.plugin(mongoosePaginate); +mySchema.plugin(mongoosePaginate); -MySchema.paginate({}, { +MyModel.paginate({}, { page: 2, limit: 10 }) .spread(function(questions, pageCount, itemCount) { @@ -92,10 +97,10 @@ MySchema.paginate({}, { ```js // advanced example usage of `mongoose-pagination` -// querying for `{ columns: 'title', { populate: 'some_ref' }, { sortBy : { title : -1 } }` items in `MySchema` +// querying for `{ columns: 'title', { populate: 'some_ref' }, { sortBy : { title : -1 } }` items in `MyModel` // paginating by second page, 10 items per page (10 results, page 2) -MySchema.paginate( +MyModel.paginate( {}, { page: 2, @@ -114,7 +119,7 @@ MySchema.paginate( ```js // populating more than one ref -MySchema.paginate({}, { +MyModel.paginate({}, { page: 2, limit: 10, columns: 'title', @@ -130,7 +135,7 @@ MySchema.paginate({}, { // selecting specific field for population // -MySchema.paginate({}, { +MyModel.paginate({}, { columns: 'title', populate: [ {