Сергей Матвеенко: MongoEngine: NoORM for NoSQL
Upcoming SlideShare
Loading in...5
×
 

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

on

  • 1,575 views

 

Statistics

Views

Total Views
1,575
Views on SlideShare
1,295
Embed Views
280

Actions

Likes
0
Downloads
16
Comments
0

5 Embeds 280

http://pycon.ru 212
http://pep8.ru 61
http://ru.pycon.org 5
http://www.pycon.ru 1
http://hghltd.yandex.net 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

  • 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 queries/sec)● open source (db: AGPL, drivers: Apache)
  • RDBMS vs MongoDB RDBMS MongoDBdata DB + Driver DB + PyMongoaggregationconstraints Applicationvalidationcascade updatesbusiness logic Application
  • RDBMS vs MongoDB RDBMS MongoDBdata DB + Driver DB + PyMongoaggregationconstraints MongoEnginevalidationcascade updatesbusiness logic Application Application
  • 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" }
  • 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" }
  • 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)
  • 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)
  • Updating with MongoEngineCreatingdb.character.save( {name: {first: John, last: Conor}, rating: 42})jc = Character( name=CharacterName(first=John, last=Conor), rating=42)jc.save()
  • 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)
  • 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
  • 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
  • Performance
  • 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)
  • 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…
  • Questions? Serge Matveenko (github.com/lig) mongoengine.org www.mongodb.org Thanks to Ross Lawley (github.com/rozza) Elena Voronina :)