Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to connect with MongoDB Atlas? #3

Open
mannerism opened this issue Nov 1, 2022 · 1 comment
Open

How to connect with MongoDB Atlas? #3

mannerism opened this issue Nov 1, 2022 · 1 comment

Comments

@mannerism
Copy link

Hello,

First of all, great work you've done to provide this tool.
Is there a way for me to connect pandas with mongodb atlas URI?

@pakallis
Copy link
Owner

pakallis commented Nov 12, 2022

Hi @mannerism!

Thanks!

To connect to MongoDB Atlas you can use something like that:

import pymongo
import pdmongo as pdm
import pandas as pd
from urllib.parse import quote_plus
from pymongo import MongoClient

url = f"mongodb+srv://<username>:{quote_plus('<password>')}@{'<cluster>?retryWrites=true&w=majority'}"

client = MongoClient(url)
df = pd.DataFrame({"A": [1,2]})
df.to_mongo("TestCollection", client['db'])
ddf = pdm.read_mongo("TestCollection", [], client['db'])

Where and are your MongoDB Atlas username and password and is the MongoDB Atlas cluster you want to connect to.

You can retrieve those details by clicking "Connect" in MongoDB atlas web UI.

Note

Make sure you have updated to the latest version of this library as I have fixed some issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants