How do I make MongoDB to C++ connection for multiple programs uniquely?

Skip to first unread message

Govardhan Veer

Jun 1, 2017, 12:42:26 PM6/1/17
As I am new to c++11 and followed a documentation provided by mongoDB. I am able make a connection to mongo and able to insert and fetch content to/from it.
But uri's scope is limited to my main(), it can not pass to other functions which are defined in other .cpp files.
So I wanted to make a connection which will creates a unique instance of mongo cxx::uri params for my each program, so that I won't need to specify the connection params like IP,Port,User,Password etc every time. In short a config file should have these params and which would be read by a .cpp program, which results into instance of mongo cxx::uri
So please let me know how do I go ahead with C++ in detail steps.

Evan Wies

Jun 1, 2017, 1:00:36 PM6/1/17
This is not a MongoDB or BSON issue.  Here’s a Stack Overflow page that covers this [1].

I like to use Boost.ProgramOptions [2].  It can be a little confusing at first, but is quite powerful and typesafe.  I often feed the results into a  Boost.PropertyTree [3] to have both CLI options and JSON configuration files (but it also supports INI and XML formats).


You received this message because you are subscribed to the Google Groups "BSON" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit
Reply all
Reply to author
0 new messages