Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-575

error compiling the example code in the wiki

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: Documentation
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I am trying to compile the code at the bottom of https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-%28New-Driver%29.

      First thing is that pkg-config mongocxx fails for me. The pkgconfig file I have installed is {{ /usr/local/lib/pkgconfig/libmongocxx.pc}}. Running pkg-config libmongocxx works fine.

      When using the modified command, I get:

      $ c++ --std=c++11 hellomongo.cpp -o hellomongo $(pkg-config --cflags --libs libmongocxx)
      hellomongo.cpp: In function ‘int main(int, char**)’:
      hellomongo.cpp:14:21: error: use of ‘document’ before deduction of ‘auto’
           auto document = document{} << "hello" << "world";
                           ^
      hellomongo.cpp:14:32: error: expected ‘,’ or ‘;’ before ‘<<’ token
           auto document = document{} << "hello" << "world";
      

      Modifying the code slightly I can compile it:

      $ diff -Naur hellomongo.cpp hellomongo1.cpp 
      --- hellomongo.cpp	2015-04-01 14:38:40.497741887 -0700
      +++ hellomongo1.cpp	2015-04-01 14:22:11.404623680 -0700
      @@ -9,9 +9,10 @@
       int main(int, char**) {
           mongocxx::instance inst{};
           mongocxx::client conn{};
      -
      +    bsoncxx::builder::stream::document document{};
      +    
           auto collection = conn["testdb"]["testcollection"];
      -    auto document = document{} << "hello" << "world";
      +    document << "hello" << "world";
       
           collection.insert_one(document.view());
           auto cursor = collection.find({});
      

            Assignee:
            adam.midvidy Adam Midvidy (Inactive)
            Reporter:
            yhager Yuval Hager
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: