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

Not a legal mongodb url address provided

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    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!

      Attachments

        Activity

          People

            Unassigned Unassigned
            1921shanghai@gmail.com 莫 莫
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: