-
-
Save ryanbekabe/48fe895186a7fa29c13ddc1f29f4f417 to your computer and use it in GitHub Desktop.
CRUD for MongoDB with Pymongo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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