[CXX-575] error compiling the example code in the wiki Created: 01/Apr/15  Updated: 20/Jun/15  Resolved: 01/Apr/15

Status: Closed
Project: C++ Driver
Component/s: Documentation
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Trivial - P5
Reporter: Yuval Hager Assignee: Adam Midvidy
Resolution: Done Votes: 0
Labels: documentation
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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({});



 Comments   
Comment by Yuval Hager [ 01/Apr/15 ]

Thanks for the tip. I'm able to successfully compile examples/mongocxx/create.cpp with no changes.. not sure why those behave differently yet..

Comment by Adam Midvidy [ 01/Apr/15 ]

Note that there are additional examples in the "examples" directory of the source tree.

Comment by Adam Midvidy [ 01/Apr/15 ]

Hi yhager, I will correct the wiki documentation. Thanks for the corrections.

Generated at Wed Feb 07 21:59:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.