What's the equivalent function of CountDocuments before 4.0?

Hello,

I am developing a feature based on CountDocuments of Collection. But I just found this function can only be used after 4.0. Now our production server runs version 3.6, is there any other equivalent functions for 3.6? And BTW, is there any tools to help me check if the API I am using is available for specific version of mongodb. I am using golang.

Thanks,

James

Hey @Zhihong_GUO

Here are all the versions of the Go driver https://github.com/mongodb/mongo-go-driver/releases

Here is the compatibility chart for the Go drivers and mongodb version
https://docs.mongodb.com/ecosystem/drivers/go/#mongodb-compatibility

Here is the 3.6 version for count() in the mongo shell
https://docs.mongodb.com/v3.6/reference/method/db.collection.count/index.html

Sorry I do not know Go at all (thinking I should learn) but the equivalent function of countDocuments before 4.0 was count()

Hello Natac, thank you so much for the detail answer!

Hi James,

The CountDocuments function will still work with server version 3.6. You can check on the driver docs to see if something is restricted to certain versions. If nothing is specified, it should work with all supported server versions. Also, the driver will return an error if something is not compatible with your current server version.

–Isabella

1 Like

Hello Isabella,

I have tested this function on 3.6 and found it works well.

Many thanks,

James