I am using MongoDB and more specifically Mongoose. I've recently been getting rid of some deprecation warnings from updating mongo and mongoose.
Some of my queries might as shown:
const count = await Badge.find(query).count().exec()
I have since changed this to
const count = Badge.find(query).countDocuments().exec()
and viola the depracation warning is gone. However, reading the documentation at MongoDB it seems that it should be written like this:
const count = Badge.countDocuments(query)
All of the above return the exact same thing. Obviously the latter two are the ones I want because of the depracation of count().
What is the difference between the second two and should I prefer one over the other?