MongoEngineNoORM for NoSQL   Serge Matveenko    github.com/lig   PyCon Russia 2013
Quick MongoDB introNoSQL document-oriented database● scalable (auto-sharding, replication)● high-performance (~104-105 que...
RDBMS vs MongoDB                  RDBMS         MongoDBdata              DB + Driver   DB + PyMongoaggregationconstraints ...
RDBMS vs MongoDB                  RDBMS         MongoDBdata              DB + Driver   DB + PyMongoaggregationconstraints ...
How it looksMongoEngine   class CharacterName(EmbeddedDocument):                  first = StringField()                  l...
How it looks(MongoEngine 0.8)MongoEngine   class CharacterName(EmbeddedDocument):                  first = StringField()  ...
Querying with MongoEngineSimpledb.character.find({name.first: John})Character.objects(name__first=John)db.character.find({...
Querying with MongoEngineMap/Reducedb.character.mapReduce(map_f, reduce_f, {out: mr_col});db.mr_col.find();Character.objec...
Updating with MongoEngineCreatingdb.character.save(  {name: {first: John, last: Conor}, rating: 42})jc = Character(   name...
Updating with MongoEngineAtomic updatesdb.character.update(  {name: {first: "John", last: "Conor"}},  {$set: {"name.last":...
Under the hood                "C" BSON   MongoDB                           PyMongo                  MongoEngine           ...
Under the hood                "C" BSON   MongoDB                           PyMongo                  MongoEngine           ...
Performance
Django integrationOut of the box● authentication backend● session engine● GridFSStorageThird party● stephrdev/django-mongo...
Customizing things(added today. sorry:)●   SequenceField(value_decorator=func)●   StringField(regex=r…)●   URLField(verify...
Questions?    Serge Matveenko (github.com/lig)           mongoengine.org           www.mongodb.org              Thanks to ...
Upcoming SlideShare
Loading in …5
×

Сергей Матвеенко: MongoEngine: NoORM for NoSQL

1,586 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,586
On SlideShare
0
From Embeds
0
Number of Embeds
354
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Сергей Матвеенко: MongoEngine: NoORM for NoSQL

  1. 1. MongoEngineNoORM for NoSQL Serge Matveenko github.com/lig PyCon Russia 2013
  2. 2. Quick MongoDB introNoSQL document-oriented database● scalable (auto-sharding, replication)● high-performance (~104-105 queries/sec)● open source (db: AGPL, drivers: Apache)
  3. 3. RDBMS vs MongoDB RDBMS MongoDBdata DB + Driver DB + PyMongoaggregationconstraints Applicationvalidationcascade updatesbusiness logic Application
  4. 4. RDBMS vs MongoDB RDBMS MongoDBdata DB + Driver DB + PyMongoaggregationconstraints MongoEnginevalidationcascade updatesbusiness logic Application Application
  5. 5. How it looksMongoEngine 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" }
  6. 6. How it looks(MongoEngine 0.8)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" }
  7. 7. Querying with MongoEngineSimpledb.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)
  8. 8. Querying with MongoEngineMap/Reducedb.character.mapReduce(map_f, reduce_f, {out: mr_col});db.mr_col.find();Character.objects.map_reduce(map_f, reduce_f, mr_col)
  9. 9. Updating with MongoEngineCreatingdb.character.save( {name: {first: John, last: Conor}, rating: 42})jc = Character( name=CharacterName(first=John, last=Conor), rating=42)jc.save()
  10. 10. Updating with MongoEngineAtomic updatesdb.character.update( {name: {first: "John", last: "Conor"}}, {$set: {"name.last": "Connor"}})Character.objects( name=CharacterName(first=John, last=Conor)).update(set__name__last=Connor)
  11. 11. Under the hood "C" BSON MongoDB PyMongo MongoEngine Module s es pe ass data tiv e ty e cl Bina ry na ativ yt hon De clar P JavaScript Console
  12. 12. Under the hood "C" BSON MongoDB PyMongo MongoEngine Module s es pe ass data tiv e ty e cl Bina ry na ativ yt hon De clar P JavaScript Console
  13. 13. Performance
  14. 14. Django integrationOut of the box● authentication backend● session engine● GridFSStorageThird party● stephrdev/django-mongoforms (Model Forms port)● wpjunior/django-mongotools (forms, generic views)● lig/django-registration-me (django-registration port)
  15. 15. 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, dont forget metaclass!● Any metamagic your like…
  16. 16. Questions? Serge Matveenko (github.com/lig) mongoengine.org www.mongodb.org Thanks to Ross Lawley (github.com/rozza) Elena Voronina :)

×