How to use mongocxx cursor without connecting to physical server for test purpose

Hi,

I am writing google tests on the code using mongocxx 3.6.1. I want to create a cursor for test purpose following the example (mongo-cxx-driver/examples/mongocxx/tailable_cursor.cpp at master · mongodb/mongo-cxx-driver · GitHub). As the default uri is localhost:27017, I get the exception when calling cursor.begin():
No suitable servers found (serverSelectionTryOnce set): [connection refused calling ismaster on ‘localhost:27017’]: generic server error"

Is there a way to set up the cursor not trying to connect to any server and just let cursor.begin() complete without exception?

Thanks.

Hi @Yudong_Sun

As far as I know, this isn’t feasible. cursor.begin() actually iterates the cursor.

You could consider catching the exception and just ignoring it.

Hi @Rishabh_Bisht ,

Thanks for your reply. I will do in that way.