Book description
Learn how to leverage MongoDB with your Python applications, using the hands-on recipes in this book. You get complete code samples for tasks such as making fast geo queries for location-based apps, efficiently indexing your user documents for social-graph lookups, and many other scenarios.
This guide explains the basics of the document-oriented database and shows you how to set up a Python environment with it. Learn how to read and write to MongoDB, apply idiomatic MongoDB and Python patterns, and use the database with several popular Python web frameworks. You’ll discover how to model your data, write effective queries, and avoid concurrency problems such as race conditions and deadlocks.
The recipes will help you:
- Read, write, count, and sort documents in a MongoDB collection
- Learn how to use the rich MongoDB query language
- Maintain data integrity in replicated/distributed MongoDB environments
- Use embedding to efficiently model your data without joins
- Code defensively to avoid keyerrors and other bugs
- Apply atomic operations to update game scores, billing systems, and more with the fast accounting pattern
- Use MongoDB with the Pylons 1.x, Django, and Pyramid web frameworks
Table of contents
-
MongoDB and Python
- SPECIAL OFFER: Upgrade this ebook with O’Reilly
- Preface
- 1. Getting Started
-
2. Reading and Writing to MongoDB with Python
- Connecting to MongoDB with Python
- Getting a Database Handle
- Inserting a Document into a Collection
- Write to a Collection Safely and Synchronously
- Guaranteeing Writes to Multiple Database Nodes
- Introduction to MongoDB Query Language
- Reading, Counting, and Sorting Documents in a Collection
- Updating Documents in a Collection
- Deleting Documents from a Collection
- MongoDB Query Operators
- MongoDB Update Modifiers
-
3. Common MongoDB and Python Patterns
- A Uniquely Document-Oriented Pattern: Embedding
- Fast Lookups: Using Indexes with MongoDB
- Location-based Apps with MongoDB: GeoSpatial Indexing
- Code Defensively to Avoid KeyErrors and Other Bugs
- Update-or-Insert: Upserts in MongoDB
- Atomic Read-Write-Modify: MongoDB’s findAndModify
- Fast Accounting Pattern
- 4. MongoDB with Web Frameworks
- About the Author
- Colophon
- SPECIAL OFFER: Upgrade this ebook with O’Reilly
Product information
- Title: MongoDB and Python
- Author(s):
- Release date: September 2011
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781449317096
You might also like
book
Using Asyncio in Python
If you’re among the Python developers put off by asyncio’s complexity, it’s time to take another …
book
Effective Python: 90 Specific Ways to Write Better Python, 2nd Edition
Updated and Expanded for Python 3 It’s easy to start developing programs with Python, which is …
book
Refactoring: Improving the Design of Existing Code
Fully Revised and Updated–Includes New Refactorings and Code Examples “Any fool can write code that a …
book
Essential SQLAlchemy, 2nd Edition
Dive into SQLAlchemy, the popular, open-source code library that helps Python programmers work with relational databases …