title: Getting started with MongoDB C++ driver in Windows
body: <p>Trying to set up a simple <code>MongoDB</code> database connection in Windows 7, using the <code>C++ driver</code>. I'm using <code>Visual C++ compiler 19</code> for <code>x86</code>, <code>32-bit MongoDB 3.0.6</code>, <code>Boost 1_59_0</code>, <code>Mongo legacy 1.0.5 C++ driver</code>.</p>
  
  <p>Driver compiles OK using the command</p>
  
  <pre><code>scons --cpppath=d:\boost_1_59_0 --libpath=d:\boost_1_59_0\stage\lib --msvc-host-arch=x86 install
  </code></pre>
  
  <p>Program is</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  #include &lt;WinSock2.h&gt;
  #include &lt;windows.h&gt;
  
  #include "mongo/client/dbclient.h"
  
  void run() {
    mongo::DBClientConnection c;
    c.connect("localhost");
  }
  
  int main() {
    try {
      run();
      std::cout &lt;&lt; "connected ok" &lt;&lt; std::endl;
    } catch( const mongo::DBException &amp;e ) {
      std::cout &lt;&lt; "caught " &lt;&lt; e.what() &lt;&lt; std::endl;
    }
    return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>Program compiles using </p>
  
  <pre><code>cl /EHsc /I"c:\mongo-cxx-driver-legacy-1.0.5\build\install\include" /I"d:\boost_1_59_0" /DSTATIC_LIBMONGOCLIENT mdb.cpp c:\mongo-cxx-driver-legacy-1.0.5\build\install\lib\libmongoclient-s.lib /link /LIBPATH:"D:\boost_1_59_0\stage\lib" ws2_32.lib
  </code></pre>
  
  <p>But when I run the program, get the error message</p>
  
  <p>caught can't connect couldn't initialize connection to <code>localhost</code>, address is invalid</p>
  
  <p>The <code>server</code> is running OK as I can access it through the <code>shell</code>, add records etc.</p>
  
  <p>This is my first time programming <code>MongoDB</code> and I'm kind of stuck. Any suggestions?</p>