Keeping Cool
Keeping Cool

Reputation: 65

Connecting to Remote MongoDB Server with Python

I have a script that I wrote to query mongodb in python I am using PyMongo. I am trying to use this script to connect to a remote MongoDB server and then run the query within the script and then I want to be able to dump the data I get back from the mongodb into a file.

What are the parameters I need to have at the top of the script to connect to this database, use my username and password, switch to the correct database and then run the query?

Upvotes: 3

Views: 8353

Answers (1)

daveh
daveh

Reputation: 3706

Couple of options.

First you could provide a MongoDB URI which can be provided to the MongoClient as an argument. Then you can switch as needed using the standard methods for getting a database once connected.

Alternately, you can connect as normal, use the getting a database once connected method to get the desired database and then use the authenticate function to authenticate against the database.

Upvotes: 2

Related Questions