Open ilaipi opened 7 years ago
Right now you can't do that in a general way.
What do you think about this possible in the future solution (with transform
function)? https://github.com/edwardhotchkiss/mongoose-paginate/issues/83#issuecomment-208747602
Just in case you wanna still wanna do this
function pagination(query, options) {
const self = this
return new Promise(function(resolve, reject) {
co(function*() {
const result = yield self.paginate(query, options)
// clean
result.offset = options.offset
result.data = result.docs
delete result.docs
// resolve
resolve(result)
}).then(resolve, reject)
})
}
schema.statics.pagination = pagination
Is how I achieved it. Basically just proxying the result through another function
I'm interested in such function as well. My coding style enforces no abbreviations.
ES6 version:
schema.statics.pagination = async (query, options) => {
// run normal pagination function first
const result = await this.paginate(query, options)
// clean
result.offset = options.offset;
result.data = result.docs;
delete result.docs;
// resolve
return result;
}
Great @jdegger, will try that!
Maybe add init params for this?
any way to do that? thanks