How to connect to MongoDB

Hi!
I am using guide from Database Library | ROBOT FRAMEWORK
There is mentioned “To connect to a database, you also need to install a Python Module adhearing to the Python Database API Specification v2.0.
You can find a list of supported database modules here.”
There is no MongoDB in the DatabaseInterfaces - Python Wiki.
So what should I use?
Could someone suggest?

Hi @Vitaly,

MongoDB is a NoSQL database, not a traditional SQL database.

From what I remember (it’s been quite some years since I last looked at MongoDB) you access it via JSON over http calls like most other NoSQL databases.

There are a few options:

  • Probably the easiest is to try the robotframework-mongodb-library, it’s not been updated in a while, hopefully that’s because no issues have been found :crossed_fingers:
  • The python module for MongoDB is well documented, so creating some python keywords to do the actions you need shouldn’t be hard, there’s a good example of how to query a db with the python module here, to get you started
  • Another option is to just do the queries to the MongoDB server directly with RequestsLibrary

Whichever you choose depends on what you need, but there are plenty of options to connect to MongoDB (there are other options too, but these are probably the best ones).

Hope that’s what you needed,

Dave.

Thank you. I tried library

1 Like

The library doesn’t seem to work.
“Connect to mongodb” returns pass/success even when the url/password is incorrect…
If you try to call anything else e.g. Get mongodb databases, it throws the error “TypeError: ‘Database’ object is not callable”
I tried all possible versions of this package, but none of them work.

As @damies13 said, the url he pointed to is a repo that doesn’t seem to be updates in like 4-5 years. PyPi shows the “latest” release of the package to be from github repo that has been deleted since. Googling refers to 3rd repository. Looks like this particular package has had various maintainers at the time but no real continiunity as single project…

Going thru github repository insights, this fork: GitHub - crnormand/robotframework-mongodb-library seems to have been touched as recently as in 5 months so it might be in better shape.

I dont know if this is in pypi but pip can install directly from github in most cases via

pip install git+https://github.com/crnormand/robotframework-mongodb-library.git

Lastly, it did look like the library name was now 4 at the end.

1 Like

As I wrote: “I tried all possible versions of this package, but none of them work.”
I also gave that one a try but the error is the same.

Hi! I am using now robot-mongodb-library · PyPI it’s working.

1 Like