简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM