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
270
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
93
Build a container on Gitlab CI quest — Game Walkthrough
lig
0
180
Mnj — The MongoDB library which feels good
lig
0
130
Writing Dockerfile for a Python project the right way
lig
0
330
Pyventory for Ansible
lig
0
180
What time is it now?
lig
1
300
100% Test Covɘrage
lig
2
140
What in fact is this Python?
lig
2
160
Mnj — the MongoDB library which does it right
lig
1
250
Other Decks in Programming
See All in Programming
地域ITコミュニティの活性化とAWSに移行してみた話
yuukis
0
230
コンテナでLambdaをデプロイするときに知っておきたかったこと
_takahash
0
180
フロントエンドテストの育て方
quramy
11
2.9k
Devinのメモリ活用の学びを自社サービスにどう組み込むか?
itarutomy
0
2.1k
Go1.24 go vetとtestsアナライザ
kuro_kurorrr
2
840
リストビュー画面UX改善の振り返り
splcywolf
0
130
Kamal 2 – Get Out of the Cloud
aleksandrov
1
180
メモリウォールを超えて:キャッシュメモリ技術の進歩
kawayu
0
1.9k
Making TCPSocket.new "Happy"!
coe401_
1
130
マルチアカウント環境での、そこまでがんばらない RI/SP 運用設計
wa6sn
0
710
趣味全開のAITuber開発
kokushin
0
190
PHP で学ぶ OAuth 入門
azuki
1
130
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Designing for humans not robots
tammielis
252
25k
Documentation Writing (for coders)
carmenintech
69
4.7k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
47
2.5k
Typedesign – Prime Four
hannesfritz
41
2.6k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
390
A Tale of Four Properties
chriscoyier
158
23k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Building Applications with DynamoDB
mza
94
6.3k
RailsConf 2023
tenderlove
30
1.1k
Music & Morning Musume
bryan
47
6.5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
104
19k
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 :)