What's the equivalent function of CountDocuments before 4.0?


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.



Hey @Zhihong_GUO

Here are all the versions of the Go driver Releases · mongodb/mongo-go-driver · GitHub

Here is the compatibility chart for the Go drivers and mongodb version

Here is the 3.6 version for count() in the mongo shell

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.


1 Like

Hello Isabella,

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

Many thanks,


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.