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
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
150
Build a container on Gitlab CI quest — Game Walkthrough
lig
0
220
Mnj — The MongoDB library which feels good
lig
0
190
Writing Dockerfile for a Python project the right way
lig
0
380
Pyventory for Ansible
lig
0
210
What time is it now?
lig
1
360
100% Test Covɘrage
lig
2
200
What in fact is this Python?
lig
2
220
Mnj — the MongoDB library which does it right
lig
1
300
Other Decks in Programming
See All in Programming
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
370
JavaDoc 再入門
nagise
1
380
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
150
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
13k
A2UI という光を覗いてみる
satohjohn
1
150
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
130
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
910
OSもどきOS
arkw
0
580
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
170
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
360
Vite+ Unified Toolchain for the Web
naokihaba
0
330
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
870
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
950
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
200
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
240
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
850
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Embracing the Ebb and Flow
colly
88
5.1k
Building the Perfect Custom Keyboard
takai
2
800
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
210
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 :)