While it is very easy to connect to mongo via node.js, I wanted to write an article about using C++ to connect to this great DB. This is done under ubuntu.
Ingredients (using apt-get here will do)
- libboost1.54-all-dev (or 55, or whatever going to be the version when you read it)
Compile the driver
Don't install from repo; Drivers should be compiled and it's actually pretty easy.
- create the directory in which you want the driver to reside.
- clone this repository: git clone firstname.lastname@example.org:mongodb/mongo-cxx-driver.git
- get into the folder created by git
--prefix=$HOME/mongo-client-install --ssl installto build the target. (if you are getting scons error, you are not in the folder, or you didn't install the entire list above). Let me clear this command as you run it: it will build and install from wherever you are now, to a new location, which is your home/mongo-client-install. You might wanna change that later on, but for now, this is fine.
- You can now use your favorite IDE to create a project to use with mongo. in your IDE, make sure you don't have any residues of old installations. If you do, remove them.
- make sure you are using paths to the include folder, path to the library and the library you created.
more libraries you will need (you might need to adjust the names/path, under ubuntu64 this should be fine):
- That's all! You are now ready to write your first program.
Test program can be found here: https://github.com/talreg/mongoclient
On ubuntu 1604, you'll have gcc 5.x. the scons command should be :scons –ssl –prefix=/programs/mongocpp –c++11=on CCFLAGS="-Wno-unused-variable -Wno-maybe-uninitialized"
where prefix is where you want to driver files to be.