Autostart/Upstart Mongodb on Ubuntu 16.04 Xenial Xerus


Check for Mongodb systemctl status by:

sudo systemctl status mongod

Enable the Mongodb Autostart/upstart with system start up:

sudo systemctl enable mongod

Note: if both of the commands returning a service not found message, then check if the service entry exist in either




If not then refer to Mongodb Documentation to create the systemd service file for Ubuntu 16.04 at this path:


With this content:

Description=High-performance, schema-free document-oriented database
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

And go back to the start of this article.

Setup C++ Development Environment for MangoDB Client

The primary target for this article is to install the mongodb C++ driver for development with C++ projects.

There is a newer branch C++ 11 based driver at this point but it’s better to start with the stable legacy one.

In a normal fresh Linux system the following steps has to be go through to meet the driver building prerequisites. For a full instruction please refer to ““.

Download and build/install Boost ( or Official Guide)

Driver require a boost version >= 1.49

tar -xzvf ./boost_1_xx_x.tar.gz
cd ./boost_1_xx_x/
sudo ./b2 install

Install Python if needed (

Driver require a Python version > 2.0

Download and install Scons (

Install by RPM package or build from source.

rpm -uvh scons-x.x.x-x.noarch.rpm

Git is also needed to clone the mongo-cxx-driver

sudo yum install git


sudo apt-get install git

Git Official Guide

Build and Install the MongoDB C++ Driver

git clone
cd ./mongo-cxx-driver
git checkout legacy
sudo scons install

Important: After this step the include and lib were generated but NOT locate in proper location. Use a prefix option to build and install or move everything under /mongo-cxx-driver/build/install/ into /usr/local/

mv ./build/install/* /usr/local/

Time to build and test a sample program

Check if you have $LD_LIBRARY_PATH in valid value by


And if nothing is showed go export the lib path by

export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH

Build the test program with

g++ tutorial.cpp -pthread -lmongoclient -lboost_thread -lboost_system -lboost_regex -o tutorial

Here is a great example to connect and insert into MongoDB: Note that a initialize() has to be added into the source to avoid a coredump.

int main() {

All set!

Everything is verified with:

  • Boost_1_55_0
  • Scons-2.3.5-1.noarh.rpm
  • Mongo-cxx-driver branch legacy