Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Downloading MongoDB Drivers to use in QT
QtWS25 Last Chance

Downloading MongoDB Drivers to use in QT

Scheduled Pinned Locked Moved Solved 3rd Party Software
mongocxxmongodbc++
11 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    orsini29
    wrote on 25 Aug 2023, 17:41 last edited by orsini29
    #1

    Not sure if this is really the place I should be asking this, but from my experience everyone here has been extremely friendly and willing to help.

    I looked at many resources, including this QT thread (the following)

    • https://forum.qt.io/topic/37645/how-to-connect-mongodb-with-qt

    • https://www.mongodb.com/docs/drivers/cxx/

    My main issue seems to be right now I do not understand, how to download the MongoDB C++ driver. The documentation is not helping me, and I am sure it is useful I just do not understand it... I tried to find some videos online, but nothing I saw was really going over the installation part, which is what I can't figure out, so I assume I am stuck on the simplest of parts.

    I was just wondering if anyone has done this before, and would be willing to help me get this up and running.

    If this is simple take it easy on me :D. Thanks in advance!

    EDIT:

    So I have been at this for almost 5 hours...is this what I am supposed to be following?

    http://mongoc.org/libmongoc/current/installing.html#preparing-a-build-from-a-release-tarball

    1. Download the TAR from the github link provided in the wget command
    2. Run the tar xzf command on the file
    3. Run cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF

    Now a question on number three, is this really necessary? What's the point? I use qmake, within Qt Creator when compiling my apps, so is this necessary?

    I have a feeling it is necessary in order to compile the driver so I can use it within Qt so I can use it as a library? I have gotten further than before with having an actual file path with headers and stuff...sorry for asking simple questions

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Aug 2023, 18:02 last edited by
      #8

      You are missing the -l before the lib path.

      In the absolute your should have something like:

      LIBS += -LC:/mongo-c-driver/lib/ -lmongoc-1.0
      INCLUDEPATH += C:/mongo-c-driver/include/
      

      As for distributing your application, you don't need the header files at all. You just have to distribute the libraries if you use the dynamic version.

      On an unrelated note, you should also consider moving your project management to cmake. qmake is now legacy from a Qt point of view and projects are encouraged to use cmake in its place.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      O 1 Reply Last reply 28 Aug 2023, 18:53
      1
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 25 Aug 2023, 19:27 last edited by SGaist
        #2

        Hi,

        On which OS are you ?

        In any case, AFAIK, you need libbson to write client applications.

        There's no Qt driver for NoSQL database so you have to write the client side yourself.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        O 1 Reply Last reply 25 Aug 2023, 19:40
        1
        • S SGaist
          25 Aug 2023, 19:27

          Hi,

          On which OS are you ?

          In any case, AFAIK, you need libbson to write client applications.

          There's no Qt driver for NoSQL database so you have to write the client side yourself.

          O Offline
          O Offline
          orsini29
          wrote on 25 Aug 2023, 19:40 last edited by
          #3

          @SGaist

          Hi,

          @SGaist said in Downloading MongoDB Drivers to use in QT:

          On which OS are you ?

          Windows 10.

          @SGaist said in Downloading MongoDB Drivers to use in QT:

          There's no Qt driver for NoSQL database so you have to write the client side yourself.

          Sorry if this is a silly question, but by writing the client side myself what exactly do you mean? Basically all the operations of insertion, updating, deleting, etc.?

          The goal is to have an application connected to a cloud database (SQL or NoSQL). The only reason I chose MongoDB Atlas (the cloud version), is because I have far more experience in mongo vs any other DB, as well I know MongoDB Atlas has free tiers in which I can just use them for project like so, rather than having to purchase a plan for another cloud DB.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 25 Aug 2023, 19:50 last edited by
            #4

            What I meant is that there's no abstraction for NoSQL as there is for SQL. With the Qt SQL module, you basically open the connection and then write your queries.

            You don't have the same option with NoSQL so you will have to write stuff like described in the MongoDB C++ tutorial. That's what I meant by client side.

            By the way, I was wrong about libbson, I have mixed it with a different library, sorry.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            O 1 Reply Last reply 25 Aug 2023, 19:55
            1
            • S SGaist
              25 Aug 2023, 19:50

              What I meant is that there's no abstraction for NoSQL as there is for SQL. With the Qt SQL module, you basically open the connection and then write your queries.

              You don't have the same option with NoSQL so you will have to write stuff like described in the MongoDB C++ tutorial. That's what I meant by client side.

              By the way, I was wrong about libbson, I have mixed it with a different library, sorry.

              O Offline
              O Offline
              orsini29
              wrote on 25 Aug 2023, 19:55 last edited by
              #5

              @SGaist

              @SGaist said in Downloading MongoDB Drivers to use in QT:

              What I meant is that there's no abstraction for NoSQL as there is for SQL. With the Qt SQL module, you basically open the connection and then write your queries.

              Okay, thank you for clarifying this.

              As for the link you had sent, I have not come across that one yet, surprisingly from all the ones I have been looking at, and I will take a look. Although, with the one I had followed I ran CMake on my TAR downloaded from the link (here), and I got a bunch of Visual Code files. I was a bit confused how this would be used in Qt, or if I was supposed to run a qmake on it or something... I am using MinGw32 for the compiler, maybe I need to switch to MSVC if I were to do this?

              S 1 Reply Last reply 25 Aug 2023, 20:09
              0
              • O orsini29
                25 Aug 2023, 19:55

                @SGaist

                @SGaist said in Downloading MongoDB Drivers to use in QT:

                What I meant is that there's no abstraction for NoSQL as there is for SQL. With the Qt SQL module, you basically open the connection and then write your queries.

                Okay, thank you for clarifying this.

                As for the link you had sent, I have not come across that one yet, surprisingly from all the ones I have been looking at, and I will take a look. Although, with the one I had followed I ran CMake on my TAR downloaded from the link (here), and I got a bunch of Visual Code files. I was a bit confused how this would be used in Qt, or if I was supposed to run a qmake on it or something... I am using MinGw32 for the compiler, maybe I need to switch to MSVC if I were to do this?

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 25 Aug 2023, 20:09 last edited by
                #6

                The goal is not that you integrate their code into your project but that you build their libraries and then use them in your code.

                Based one the article they seem to use Visual Studio but you can try with MinGW by modifying the tool in their configuration example.

                Note that they use cmake as project management tool. I would advise to do the same for your project as qmake is now deprecated. It can still be used for client projects but the Qt framework has switch to cmake for its build system.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                O 1 Reply Last reply 28 Aug 2023, 14:04
                1
                • S SGaist
                  25 Aug 2023, 20:09

                  The goal is not that you integrate their code into your project but that you build their libraries and then use them in your code.

                  Based one the article they seem to use Visual Studio but you can try with MinGW by modifying the tool in their configuration example.

                  Note that they use cmake as project management tool. I would advise to do the same for your project as qmake is now deprecated. It can still be used for client projects but the Qt framework has switch to cmake for its build system.

                  O Offline
                  O Offline
                  orsini29
                  wrote on 28 Aug 2023, 14:04 last edited by
                  #7

                  @SGaist said in Downloading MongoDB Drivers to use in QT:

                  The goal is not that you integrate their code into your project but that you build their libraries and then use them in your code.

                  Yes, correct.

                  So I got a little further with some research and following along with the tutorial. Although, I am still a little stuck and was wondering if you can steer me in the right direction, although if you aren't able to I understand as this is not exactly Qt related.

                  I have this folder path in my C drive (pictured below). In the include folder it has the header files, for both libmongoc-1.0 and libbson-1.0. (so you might have been correct in your previous comment). Then the lib directory has these, pictured below.

                  a28b9080-e517-4487-a15f-0a80e55dbf80-image.png

                  7d30b010-3cb9-4ee2-9ea9-347bd642d931-image.png

                  I added this into my *.pro file, and it builds fine.

                  LIBS += C:/mongo-c-driver/lib/mongoc-1.0.lib

                  Although once I go to use #include <mongoc/mongoc.h> I get an error saying the file cannot be found, which makes sense obviously because the file is not in that relative path.

                  If I plan on packaging this application to be used on another desktop, how would I go about including the headers, along with the lib file to be used? I know that including the headers within the code is not the answer, as you had stated below.

                  @SGaist said in Downloading MongoDB Drivers to use in QT:

                  The goal is not that you integrate their code into your project but that you build their libraries and then use them in your code.

                  I will be looking into this in the meantime, and update my comment if I end up figuring this out. I have a feeling it is something simple I am completely overlooking. Thanks again @SGaist.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 28 Aug 2023, 18:02 last edited by
                    #8

                    You are missing the -l before the lib path.

                    In the absolute your should have something like:

                    LIBS += -LC:/mongo-c-driver/lib/ -lmongoc-1.0
                    INCLUDEPATH += C:/mongo-c-driver/include/
                    

                    As for distributing your application, you don't need the header files at all. You just have to distribute the libraries if you use the dynamic version.

                    On an unrelated note, you should also consider moving your project management to cmake. qmake is now legacy from a Qt point of view and projects are encouraged to use cmake in its place.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    O 1 Reply Last reply 28 Aug 2023, 18:53
                    1
                    • S SGaist
                      28 Aug 2023, 18:02

                      You are missing the -l before the lib path.

                      In the absolute your should have something like:

                      LIBS += -LC:/mongo-c-driver/lib/ -lmongoc-1.0
                      INCLUDEPATH += C:/mongo-c-driver/include/
                      

                      As for distributing your application, you don't need the header files at all. You just have to distribute the libraries if you use the dynamic version.

                      On an unrelated note, you should also consider moving your project management to cmake. qmake is now legacy from a Qt point of view and projects are encouraged to use cmake in its place.

                      O Offline
                      O Offline
                      orsini29
                      wrote on 28 Aug 2023, 18:53 last edited by orsini29
                      #9

                      @SGaist

                      @SGaist said in Downloading MongoDB Drivers to use in QT:

                      As for distributing your application, you don't need the header files at all. You just have to distribute the libraries if you use the dynamic version.

                      By dynamic version, I assume you mean using a DLL? I see DLLs within mongo-c-driver/bin, (see below). Would this just be as simple as putting the DLLs into the application path? Or would the header files be needed in this case? I know you said they would not be needed, although just a little confused on how else the function definitions would be referenced in that regard.

                      497dc8ed-a0d1-425f-a8b8-7bff3e9f29c9-image.png

                      @SGaist said in Downloading MongoDB Drivers to use in QT:

                      On an unrelated note, you should also consider moving your project management to cmake. qmake is now legacy from a Qt point of view and projects are encouraged to use cmake in its place.

                      As for this, I will definitely start migrating some stuff over. I have been using qmake ever since I started programming with Qt, so it will be a bit of a learning curve (again) on how to change everything over, so if you have any good information please let me know! Otherwise Google is my friend!

                      I will definitely be marking this topic as solved once I hear back from you. Unsure if the thread locks when it becomes solved. Thanks again!

                      Edit:

                      Also, would using cmake over qmake get rid of the *.pro file configuration? Or is that completely irrelevant?

                      S 1 Reply Last reply 28 Aug 2023, 19:29
                      0
                      • O orsini29
                        28 Aug 2023, 18:53

                        @SGaist

                        @SGaist said in Downloading MongoDB Drivers to use in QT:

                        As for distributing your application, you don't need the header files at all. You just have to distribute the libraries if you use the dynamic version.

                        By dynamic version, I assume you mean using a DLL? I see DLLs within mongo-c-driver/bin, (see below). Would this just be as simple as putting the DLLs into the application path? Or would the header files be needed in this case? I know you said they would not be needed, although just a little confused on how else the function definitions would be referenced in that regard.

                        497dc8ed-a0d1-425f-a8b8-7bff3e9f29c9-image.png

                        @SGaist said in Downloading MongoDB Drivers to use in QT:

                        On an unrelated note, you should also consider moving your project management to cmake. qmake is now legacy from a Qt point of view and projects are encouraged to use cmake in its place.

                        As for this, I will definitely start migrating some stuff over. I have been using qmake ever since I started programming with Qt, so it will be a bit of a learning curve (again) on how to change everything over, so if you have any good information please let me know! Otherwise Google is my friend!

                        I will definitely be marking this topic as solved once I hear back from you. Unsure if the thread locks when it becomes solved. Thanks again!

                        Edit:

                        Also, would using cmake over qmake get rid of the *.pro file configuration? Or is that completely irrelevant?

                        S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 28 Aug 2023, 19:29 last edited by
                        #10

                        The header is only required when you develop your code. At runtime, it doesn't do anything. Your application is linked to the library.

                        Yes, it's the .dll that are required and yes again, you deploy them along with your application executable.

                        Yes, you will use a CMakeLists.txt file in place of the .pro file. There's a small helper script call qmake2cmake that you can use to get your porting effort started.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        O 1 Reply Last reply 28 Aug 2023, 19:31
                        1
                        • S SGaist
                          28 Aug 2023, 19:29

                          The header is only required when you develop your code. At runtime, it doesn't do anything. Your application is linked to the library.

                          Yes, it's the .dll that are required and yes again, you deploy them along with your application executable.

                          Yes, you will use a CMakeLists.txt file in place of the .pro file. There's a small helper script call qmake2cmake that you can use to get your porting effort started.

                          O Offline
                          O Offline
                          orsini29
                          wrote on 28 Aug 2023, 19:31 last edited by
                          #11

                          @SGaist

                          Awesome. Thank you a lot, appreciate the help. I will definitely be looking into this, and if I have any other questions I'll reach out, cheers!

                          1 Reply Last reply
                          0
                          • O orsini29 has marked this topic as solved on 28 Aug 2023, 19:31

                          2/11

                          25 Aug 2023, 19:27

                          topic:navigator.unread, 9
                          • Login

                          • Login or register to search.
                          2 out of 11
                          • First post
                            2/11
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved