-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replaced deprecated count() method #153
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ function paginate(query, options, callback) { | |
} | ||
promises = { | ||
docs: docsQuery.exec(), | ||
count: this.count(query).exec() | ||
count: this.countDocuments(query).exec() | ||
}; | ||
if (lean && leanWithId) { | ||
promises.docs = promises.docs.then((docs) => { | ||
|
@@ -66,15 +66,15 @@ function paginate(query, options, callback) { | |
return Promise.all(promises).then((data) => { | ||
let result = { | ||
docs: data.docs, | ||
total: data.count, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should stay as is (data.count). Because property count is result of @estimatedDocumentCount method. |
||
total: data.countDocuments, | ||
limit: limit | ||
}; | ||
if (offset !== undefined) { | ||
result.offset = offset; | ||
} | ||
if (page !== undefined) { | ||
result.page = page; | ||
result.pages = Math.ceil(data.count / limit) || 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should stay as is (data.count). Because property count is result of @estimatedDocumentCount method. |
||
result.pages = Math.ceil(data.countDocuments / limit) || 1; | ||
} | ||
if (typeof callback === 'function') { | ||
return callback(null, result); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using countable querying you should use @estimatedDocumentCount as discussed in: Automattic/mongoose#6713.