aravindnc / mongoose-aggregate-paginate-v2

A page based custom aggregate pagination library for Mongoose with customizable labels.
MIT License
131 stars 24 forks source link

`aggregatePaginate()` method is not exist #1

Closed Yangeok closed 5 years ago

Yangeok commented 5 years ago
// models/feed.js
const mongoose = require('mongoose');
const uniqueValidator = require('mongoose-unique-validator');
const mongoosePaginate = require('mongoose-paginate-v2');

const feedsSchema = new mongoose.Schema({
  creator: String,
  title: { type: String, unique: true },
  link: String,
  pubDate: Date
});

feedsSchema.plugin(uniqueValidator);
feedsSchema.plugin(mongoosePaginate);
module.exports = mongoose.model('Feed', feedsSchema);

// query.js
const Feed = require('./models/feed');
let options = {
  page: 1,
  limit: 10
};

const aggregate = Feed.aggregate();
Feed.aggregatePaginate(aggregate, options)
  .then(results => {
    console.log(results)
}).catch(err => {
    console.log(err);
});

I followed the tutorial, but it prints a function in the console that does not have an aggregatePaginate () method. What is wrong and what should I do?

aravindnc commented 5 years ago

@Yangeok You are including the wrong package. It should be, const mongoosePaginate = require('mongoose-aggregate-paginate-v2');

Yangeok commented 5 years ago

Then you need both package mongoose-paginate-v2 and mongoose-aggregate-paginate-v2. So the npm page is not up to date?

aravindnc commented 5 years ago

mongoose-aggregate-paginate-v2 is only for aggregate. mongoose-paginate-v2 does not support aggregate.

So you may need both in your project.

Yangeok commented 5 years ago

I mistook the document. I had to look at usage in mongoose-paginate-v2 and saw usage in mongoose-aggregate-paginate-v2.

Thank you for your help.

aravindnc commented 5 years ago

@Yangeok Glad to hear that. So I'm closing the issue. Please reopen if needed. Happy Coding!