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
2
290
MongoEngine - NoORM for NoSQL
The talk about MongoEngine presented on PyCon Russia 2013.
Serge Matveenko
February 24, 2013
Tweet
Share
More Decks by Serge Matveenko
See All by Serge Matveenko
Using NSQ in Python
lig
0
120
Build a container on Gitlab CI quest — Game Walkthrough
lig
0
200
Mnj — The MongoDB library which feels good
lig
0
170
Writing Dockerfile for a Python project the right way
lig
0
360
Pyventory for Ansible
lig
0
200
What time is it now?
lig
1
340
100% Test Covɘrage
lig
2
180
What in fact is this Python?
lig
2
200
Mnj — the MongoDB library which does it right
lig
1
280
Other Decks in Programming
See All in Programming
CSC307 Lecture 06
javiergs
PRO
0
680
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.4k
CSC307 Lecture 05
javiergs
PRO
0
500
Architectural Extensions
denyspoltorak
0
280
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
690
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
160
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6k
Featured
See All Featured
Visualization
eitanlees
150
17k
Six Lessons from altMBA
skipperchong
29
4.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
170
Done Done
chrislema
186
16k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
290
Chasing Engaging Ingredients in Design
codingconduct
0
110
Skip the Path - Find Your Career Trail
mkilby
0
54
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
92
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
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 :)