[CXX-1606] 'mongocxx::cursor' could not be resolved Created: 04/Jul/18  Updated: 27/Oct/23  Resolved: 26/Jul/18

Status: Closed
Project: C++ Driver
Component/s: BSON, Release
Affects Version/s: 3.3.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Black [X] Assignee: A. Jesse Jiryu Davis
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

ubuntu 16.04
Eclipse IDE for C/C++ Developers
c++11


Issue Links:
Duplicate
is duplicated by CXX-1605 'mongocxx::cursor' could not be resolved Closed

 Description   

Hi.
This code works(i.e. it run)

 

mongocxx::instance instance{}; // This should be done only once.
 mongocxx::uri uri("mongodb://192.168.1.1:27017");
 mongocxx::client client(uri);
 mongocxx::database db = client["test"];
 mongocxx::collection coll = db["counters"];
mongocxx::cursor cursor = coll.find({});
for(auto doc : cursor) {
 std::cout << bsoncxx::to_json(doc) << "\n";
 }

But at compilation errors:

Method 'find' could not be resolved
'mongocxx::cursor' could not be resolved
 
How to make that there were no errors?

-I/usr/local/include/libbson-1.0
-I/usr/local/include/libmongoc-1.0
-I/usr/local/include/mongocxx/v_noabi
-I/usr/local/include/bsoncxx/v_noabi
-lbsoncxx -lmongocxx
-L/usr/local/lib -Wl,-rpath=/usr/local/lib

 



 Comments   
Comment by A. Jesse Jiryu Davis [ 27/Jul/18 ]

I tried compiling your code on an Ubuntu 16.04 machine and I was able to compile it without error. Here's my g++ and cmake versions:

> g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
> cmake --version
cmake version 3.11.0

I followed the installation instructions for the C Driver and C++ Driver:

http://mongoc.org/libmongoc/current/installing.html
https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/

These are the commands I ran:

curl -LO https://github.com/mongodb/mongo-c-driver/releases/download/1.12.0/mongo-c-driver-1.12.0.tar.gz
tar -xzf mongo-c-driver-1.12.0.tar.gz
cd mongo-c-driver-1.12.0/
mkdir cmake-build
cd cmake-build/
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
make
sudo make install
cd
curl -LO https://github.com/mongodb/mongo-cxx-driver/archive/r3.3.0.tar.gz
tar -xzf r3.3.0.tar.gz
cd mongo-cxx-driver-r3.3.0/build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBSONCXX_POLY_USE_STD_EXPERIMENTAL=ON -DCMAKE_CXX_STANDARD=14 ..
make
sudo make install
cd

Once I had installed the C and C++ Drivers and put your code into the following complete file:

#include <iostream>
 
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/options/find.hpp>
#include <mongocxx/uri.hpp>
 
int main(void) {
 
  mongocxx::instance instance{}; // This should be done only once.
  mongocxx::uri uri("mongodb://192.168.1.1:27017");
  mongocxx::client client(uri);
  mongocxx::database db = client["test"];
  mongocxx::collection coll = db["counters"];
  mongocxx::cursor cursor = coll.find({});
  for(auto doc : cursor) {
    std::cout << bsoncxx::to_json(doc) << "\n";
  }
}

I put this code into a file named foo.cpp and compiled it like this:

g++ -std=c++14 -I/usr/local/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/bsoncxx/v_noabi foo.cpp -lbsoncxx -lmongocxx -L/usr/local/lib -Wl,-rpath=/usr/local/lib

Comment by Black [X] [ 27/Jul/18 ]

-Please add

-#include <mongocxx/cursor.hpp>

Sorry!

I did it, It does not help.
 

Comment by A. Jesse Jiryu Davis [ 26/Jul/18 ]

Please add:

#include <mongocxx/cursor.hpp>

Generated at Wed Feb 07 22:03:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.