Python MongoDB - pymongo Tutorial



How to install pymongo using pip?

python -m pip install pymongo

How to check pymongo version using pip ?

pip list | grep pymongo

How top check pymongo version from code?

import pymongo

print("pymongo version :",pymongo.__version__)

pymongo version : 3.12.0

How to create connection with MondoDB using pymongo?

import pymongo

# connection to mongodb
mc=pymongo.MongoClient("localhost",27017)

print("Connected to mongo ...",mc)

Connected to mongo ... MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True)

How to create new database in MongoDB in Python?

import pymongo

# connection to mongodb
mc=pymongo.MongoClient("localhost",27017)

# create new database
new_db = mc["new_db"]

How to get list of database names using pymongo?

import pymongo

# connection to mongodb
mc=pymongo.MongoClient("localhost",27017)

db_list = mc.list_database_names()

for db in db_list:
    print(db)

admin
config
local




Post a Comment

Previous Post Next Post