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
260
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
63
Build a container on Gitlab CI quest — Game Walkthrough
lig
0
160
Mnj — The MongoDB library which feels good
lig
0
93
Writing Dockerfile for a Python project the right way
lig
0
290
Pyventory for Ansible
lig
0
160
What time is it now?
lig
1
240
100% Test Covɘrage
lig
2
120
What in fact is this Python?
lig
2
130
Mnj — the MongoDB library which does it right
lig
1
200
Other Decks in Programming
See All in Programming
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
210
エンターテイメント業界で利用されるAWS
demuyan
0
200
OpenTelemetry のサービスという概念について
azukiazusa1
2
1.1k
VSCodeでのDatabricks開発もお勧めしたい/I would also recommend Databricks development with VSCode.
kazumain
0
240
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
170
코틀린으로 멀티플랫폼 만들기
pangmoo
0
120
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
180
Elm Form Validation
bkuhlmann
0
500
元気予報
suu_mire0726
0
850
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
110
Git Rebase
bkuhlmann
11
1.6k
Ruby製社内ツールのGo移行
bgpat
2
330
Featured
See All Featured
Atom: Resistance is Futile
akmur
258
25k
Agile that works and the tools we love
rasmusluckow
324
20k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
Building Better People: How to give real-time feedback that sticks.
wjessup
354
18k
Art, The Web, and Tiny UX
lynnandtonic
288
19k
Building Adaptive Systems
keathley
30
1.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
154
14k
Visualization
eitanlees
135
14k
Unsuck your backbone
ammeep
662
57k
From Idea to $5000 a Month in 5 Months
shpigford
377
45k
Why You Should Never Use an ORM
jnunemaker
PRO
50
8.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
76
41k
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 :)