Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #63 from Jokero/patch-1
Update Readme: use MyModel instead of MySchema
  • Loading branch information
edwardhotchkiss committed Sep 23, 2015
2 parents 13063aa + 80f3e72 commit 80a7b16
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions README.md
Expand Up @@ -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**

Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -114,7 +119,7 @@ MySchema.paginate(
```js
// populating more than one ref

MySchema.paginate({}, {
MyModel.paginate({}, {
page: 2,
limit: 10,
columns: 'title',
Expand All @@ -130,7 +135,7 @@ MySchema.paginate({}, {
// selecting specific field for population
// <http://mongoosejs.com/docs/api.html#query_Query-populate>

MySchema.paginate({}, {
MyModel.paginate({}, {
columns: 'title',
populate: [
{
Expand Down

0 comments on commit 80a7b16

Please sign in to comment.