Connecting to MongoDB¶
Anaconda Enterprise enables you to connect to a MongoDB database to work with data in its document-oriented store.
To access MongoDB while in a notebook session, you’ll need to conda install the Python driver using the following command:
NOTE: Any packages you install from the command line are available during the current session only. If you want them to persist, add them to the project’s anaconda-project.yml
file. For more information, see Developing a project.
After you’ve installed the pymongo
driver, you can use code such as this to access MongoDB from within a notebook session:
To connect to the MongoDB server:
NOTE: This example uses the SCRAM-SHA-256
default authentication mechanism. You’ll need to change this if you are using a different mechanism.
See the PyMongo documentation for additional authentication examples.
If you need to connect to a replica set, see these examples.
Now that you’ve connected to MongoDB, you can use code such as this to access it from within a notebook session:
See Storing secrets for information about adding credentials to the platform, to make them available in your projects. Any secrets you add will be available across all sessions and deployments associated with your user account.