This patches #3131 to use collection.countDocuments instead of cursor.count which has a different behavior in the native mongodb@4.10 driver than the previously used mongojs library. Additionally, support it is deprecated.
cursor.count() will return the count of the artworks returned from the find cursor. However, what our clients are expecting is the total number of documents that will be returned from a passed-in query. This currently breaks pagination, as flagged by the editorial team 🔒 here.
const cursor = db
.collection("articles")
.find(query)
.skip(offset || 0)
.sort(sort)
.limit(limit)
// Will return the # of documents returned from the above query, factoring in the `limit`.
// If the value of `limit` is `15`, it will return `15` (or less if there are not `15` documents matching the query).
return cursor.count(cb)
// Will return the total # of documents matching the query in the whole collection
return db.collection("articles").countDocuments(query, cb)
This patches #3131 to use
collection.countDocuments
instead ofcursor.count
which has a different behavior in the nativemongodb@4.10
driver than the previously usedmongojs
library. Additionally, support it is deprecated.cursor.count()
will return the count of the artworks returned from thefind
cursor. However, what our clients are expecting is the total number of documents that will be returned from a passed-in query. This currently breaks pagination, as flagged by the editorial team 🔒 here.