Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MongoEngine - NoORM for NoSQL
Search
Serge Matveenko
February 24, 2013
Programming
290
2
Share
MongoEngine - NoORM for NoSQL
The talk about MongoEngine presented on PyCon Russia 2013.
Serge Matveenko
February 24, 2013
More Decks by Serge Matveenko
See All by Serge Matveenko
Using NSQ in Python
lig
0
140
Build a container on Gitlab CI quest — Game Walkthrough
lig
0
220
Mnj — The MongoDB library which feels good
lig
0
180
Writing Dockerfile for a Python project the right way
lig
0
380
Pyventory for Ansible
lig
0
200
What time is it now?
lig
1
350
100% Test Covɘrage
lig
2
190
What in fact is this Python?
lig
2
210
Mnj — the MongoDB library which does it right
lig
1
290
Other Decks in Programming
See All in Programming
ふにゃっとしない名前の付け方 〜哲学で茹で上げる、コシのあるソフトウェア設計〜
shimomura
0
120
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
160
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
270
cloudnative conference 2026 flyle
azihsoyn
0
170
PHPでバイナリをパースして理解するASN.1
muno92
PRO
0
450
PHPer、Cloudflare に引っ越す
suguruooki
1
160
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.9k
Building on Bluesky's AT Protocol with Ruby
mackuba
0
110
書き換えて学ぶTemporal #fukts
pirosikick
2
370
Import assertionsが消えた日~ECMAScriptの仕様はどう決まり、なぜ覆るのか~
bicstone
2
180
Agentic Elixir
whatyouhide
0
450
Explore CoroutineScope
tomoeng11
0
180
Featured
See All Featured
Discover your Explorer Soul
emna__ayadi
2
1.1k
Designing for Timeless Needs
cassininazir
0
220
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
550
Producing Creativity
orderedlist
PRO
348
40k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
280
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
180
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
1.3k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
199
73k
Transcript
MongoEngine NoORM for NoSQL Serge Matveenko github.com/lig PyCon Russia 2013
Quick MongoDB intro NoSQL document-oriented database • scalable (auto-sharding, replication)
• high-performance (~104-105 queries/sec) • open source (db: AGPL, drivers: Apache)
RDBMS vs MongoDB RDBMS MongoDB data DB + Driver DB
+ PyMongo aggregation constraints Application validation cascade updates business logic Application
RDBMS vs MongoDB RDBMS MongoDB data DB + Driver DB
+ PyMongo aggregation constraints MongoEngine validation cascade updates business logic Application Application
MongoEngine class CharacterName(EmbeddedDocument): first = StringField() last = StringField() class
Character(Document): name = EmbeddedDocumentField(CharacterName) rating = IntField() MongoDB { "_id" : ObjectId ("5125e0ee98764119e77d9b1f"), "_types" : ["Character"], "rating" : 42, "name" : {"_types" : ["CharacterName"], "last": "Connor", "_cls": "CharacterName", "first": "Sarah"}, "_cls": "Character" } How it looks
MongoEngine class CharacterName(EmbeddedDocument): first = StringField() last = StringField() class
Character(Document): name = EmbeddedDocumentField(CharacterName) rating = IntField() MongoDB { "_id" : ObjectId ("5125e0ee98764119e77d9b1f"), "rating" : 42, "name" : {"last": "Connor", "_cls": "CharacterName", "first": "Sarah"}, "_cls": "Character" } How it looks (MongoEngine 0.8)
Simple db.character.find({'name.first': 'John'}) Character.objects(name__first='John') db.character.find({rating: {$gte: 42}}).limit(5) Character.objects(rating__gte=42)[:5] db.character.find({rating: {$exists:
false}}) Character.objects(rating__exists=False) Querying with MongoEngine
Map/Reduce db.character.mapReduce(map_f, reduce_f, {out: 'mr_col'}); db.mr_col.find(); Character.objects.map_reduce(map_f, reduce_f, 'mr_col') Querying
with MongoEngine
Creating db.character.save( {name: {first: 'John', last: 'Conor'}, rating: 42}) jc
= Character( name=CharacterName(first='John', last='Conor'), rating=42) jc.save() Updating with MongoEngine
Atomic updates db.character.update( {name: {first: "John", last: "Conor"}}, {$set: {"name.last":
"Connor"}}) Character.objects( name=CharacterName(first='John', last='Conor') ).update(set__name__last='Connor') Updating with MongoEngine
Under the hood MongoDB "C" BSON Module PyMongo MongoEngine JavaScript
Console Binary data Python native types Declarative classes
Under the hood MongoDB "C" BSON Module PyMongo MongoEngine JavaScript
Console Binary data Python native types Declarative classes
Performance
Out of the box • authentication backend • session engine
• GridFSStorage Third party • stephrdev/django-mongoforms (Model Forms port) • wpjunior/django-mongotools (forms, generic views) • lig/django-registration-me (django-registration port) Django integration
Customizing things (added today. sorry:) • SequenceField(value_decorator=func) • StringField(regex=r'…') •
URLField(verify_exists=True) • … • Inherit from standard Field classes • Write your own Field classes • Inherit from BaseDocument class, don't forget metaclass! • Any metamagic your like…
Questions? Serge Matveenko (github.com/lig) mongoengine.org www.mongodb.org Thanks to Ross Lawley
(github.com/rozza) Elena Voronina :)