The document describes MongoDB, an open-source, high-performance, schema-free, document-oriented database that addresses some shortcomings of relational databases like scalability and flexibility. It discusses some key MongoDB concepts like documents, collections, indexing, embedding data, and querying capabilities. An example blog application is provided to illustrate common operations like creating, retrieving, and counting documents in a MongoDB deployment using PyMongo.
6. • Focus on performance
• Rich dynamic queries
• Secondary indexes
• Replication / failover
• Auto-sharding
• Many platforms / languages supported
7.
8. Good at
• The web
• Caching
• High volume / low value
• Scalability
9. Less good at
• Highly transactional
• Ad-hoc business intelligence
• Problems that require SQL
10. PyMongo
• Python driver for MongoDB
• Pure Python, with optional C extension
• Installation (setuptools):
easy_install pymongo
11. Document
• Unit of storage (think row)
• Just a dictionary
• Can store many Python types:
• None, bool, int, float, string / unicode,
dict, datetime.datetime, compiled re
• Some special types:
• SON, Binary, ObjectId, DBRef
17. New post
post = {“author”: “mike”,
“date”: datetime.datetime.utcnow(),
“text”: “my blog post...”,
“tags”: [“mongodb”, “python”]}
post_id = db.posts.save(post)
18. Embedding a comment
c = {“author”: “eliot”,
“date”: datetime.datetime.utcnow(),
“text”: “great post!”}
db.posts.update({“_id”: post_id},
{“$push”: {“comments”: c}})
19. Last 10 posts
query = db.posts.find()
.sort(“date”, DESCENDING)
.limit(10)
for post in query:
print post[“text”]