import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mypython"]
# install the pymongo module through pip or some other package manager
from pymongo import MongoClient
client = MongoClient("<mongodb uri>")
db = client.example_database # you can also do 'client["example_database"]'
collection = db.example_collection
for i in collection.find(): # returns a list of documents in the collection
print(i) # print collection document
# importing module
from pymongo import MongoClient
# creation of MongoClient
client=MongoClient()
# Connect with the portnumber and host
client = MongoClient(“mongodb://localhost:27017/”)
# Access database
mydatabase = client[‘name_of_the_database’]
# Access collection of the database
mycollection=mydatabase[‘myTable’]
# dictionary to be added in the database
rec={
title: 'MongoDB and Python',
description: 'MongoDB is no SQL database',
tags: ['mongodb', 'database', 'NoSQL'],
viewers: 104
}
# inserting the data in the database
rec = mydatabase.myTable.insert(record)