[CXX-1991] Not a legal mongodb url address provided Created: 14/Apr/20  Updated: 27/Oct/23  Resolved: 15/Apr/20

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

Type: Bug Priority: Major - P3
Reporter: 莫 莫 Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hello, I use mongocxx API to do some demo.

Our remote server is built on mongodb.

It can be visited via JavaScript and Python.

Currently, I want to wrap some MongoDB C++ APIs to use with other applications based on C++.

I wrote the code as:

int main() {
// The mongocxx::instance constructor and destructor initialize and shut down the driver,
// respectively. Therefore, a mongocxx::instance must be created before using the driver and
// must remain alive for as long as the driver is in use.
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_document;
mongocxx::instance inst{};

mongocxx::client conn{mongocxx::uri{"http://192.168.888.888"}};
auto db = conn["video-label"];
std::string video_id = "sf-252261";
//拿到视频
auto result = db.run_command(make_document(kvp("id", video_id)));
std::cout << bsoncxx::to_json(result) << std::endl;

try

Unknown macro: { //No need to insert, just to write. //query_top_level_find_keyboard_data(db, video_id); //query_top_level_fields_examples(db); //query_embedded_documents_examples(db); //query_arrays_examples(db); //query_array_embedded_documents_examples(db); //query_null_missing_fields_examples(db); }

catch (const std::logic_error& e)

Unknown macro: { std}

}

My launch command is:

c++ --std=c++17 find_piano_query_demo.cpp -o find_piano_query_demo -I/opt/mongo-cxx-driver/include/mongocxx/v_noabi -I/opt/mongo-cxx-driver/include/bsoncxx/v_noabi -L/usr/local/lib -lmongocxx -lbsoncxx

It is OK for compilation but report error in running:
l

ibc++abi.dylib: terminating with uncaught exception of type mongocxx::v_noabi::logic_error: an invalid MongoDB URI was provided
Abort trap: 6

Looks like this statement "mongocxx::client conn{mongocxx::uri{"http://192.168.888.888"}};" is not correct. Thus, what is the legal statement of Mongodb URL with IP address?

Since there is no clear guide for mongodb-c++ development, I just imitate some demo code, may have problem.

Thanks & Regards!



 Comments   
Comment by 莫 莫 [ 15/Apr/20 ]

Looks like use "mongodb://" instead of "http://", can resolve this problem.

Comment by Kevin Albertson [ 14/Apr/20 ]

Hi 1921shanghai@gmail.com,

The connection string should be of the form: "mongodb://192.168.888.888". The MongoDB manual includes a reference for valid connection strings: https://docs.mongodb.com/manual/reference/connection-string/

For future reference, the CXX Jira project is generally limited to bug reports or feature requests. Please feel free to post any questions on the MongoDB Community forum in the Drivers, ODMs, and Connectors category tagged with cxx-driver.

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