Skip to content

Instantly share code, notes, and snippets.

@ryanbekabe
Forked from cjgiridhar/mongoDB.py
Created June 22, 2019 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanbekabe/48fe895186a7fa29c13ddc1f29f4f417 to your computer and use it in GitHub Desktop.
Save ryanbekabe/48fe895186a7fa29c13ddc1f29f4f417 to your computer and use it in GitHub Desktop.
CRUD for MongoDB with Pymongo
import pymongo
from pymongo import Connection
conn = Connection()
db = conn['myDB']
collection = db['language']
#Creating a collection
db.language.insert({"id": "1", "name": "C", "grade":"Boring"})
db.language.insert({"id": "2", "name":"Python", "grade":"Interesting"})
#Reading it
print "After create\n",list(db.language.find())
#Updating the collection
db.language.update({"name":"C"}, {"$set":{"grade":"Make it interesting"}})
print "After update\n",list(db.language.find())
#Deleting the collection
db.language.drop()
print "After delete\n", list(db.language.find())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment