How do I connect mongodb?

Viewed 20

I'm tryna connect to mongodb through python but it's kinda different from javascript so its not working, please someone help a bit?

db = MongoClient.connect("mongodb://host:port") # Changed that in the real code to my own server which workes

collection = db.test_db

1 Answers

welcome to stackoverflow.

Python syntax is different from JavaScript, and might get some new coders confused...

Try this instead:


mongodb = MongoClient("mongodb://host:port")
db = mongodb["db_name"]
col = db["collection_name"]

that oughta do it!

Related