Pymongo
from pymongo import MongoClient
client = MongoClient('mongodb://localhost:27017/')
db = client.test_database
posts = db.test_collection
post_id = posts.insert_one(post).inserted_idConnecting to Mongo Atlas
import ssl
client = pymongo.MongoClient('[atlas...uri]', ssl=True, ssl_cert_reqs=ssl.CERT_NONE)QUERYING
db.student.find({}, {roll:1, _id:0}) #Projection: find all students and return their roll and not their id(id returned by default
dbClasses.find({"location": { '$regex': '.*' + building + '.*'}, "day": WEEKDAYS[weekday]})Inserting
Last updated