Upgrade to Pro — share decks privately, control downloads, hide ads and more …

プログラミング生放送勉強会14@品川

 プログラミング生放送勉強会14@品川

14, 15枚目のスライド、mongoengine.connectionを呼んでいますが、mongoengine.connectの誤りです。時間のない中でスライド作ったので気づきませんでした。すみません。

D12b0581b8218af98bf3014af3eeaac3?s=128

Kohei YOSHIDA

April 07, 2012
Tweet

Transcript

  1. Python Meets MongoDB 2 0 1 2 / 0 4

    / 0 7 ( S a t . ) ϓ ϩ ά ϥ ϛ ϯ ά ੜ ์ ૹ 1 4 t h
  2. ͓લͩΕΑ 1995(ฏ੒7)೥ੜ·Ε, ߴߍ2೥ੜ Pythonista, WebܥϓϩάϥϚ @yosida95, id:yosida95 http://yosida95.com/

  3. Python Meets MongoDB

  4. Python Meets MongoDB εςϚ

  5. εςϚ͠ʹདྷͨ΋ͷ #TwitActivity http://twit.yosida95.com/ OAuthೝূͨ͠ϢʔβʔͷTwitter্Ͱͷձ ࿩Λin_reply_toʹج͖ͮऩू࣌͠ܥྻʹද ࣔ͢ΔαʔϏε

  6. εςϚ͠ʹདྷͨ΋ͷ #TwitActivity http://twit.yosida95.com/ OAuthೝূͨ͠ϢʔβʔͷTwitter্Ͱͷձ ࿩Λin_reply_toʹج͖ͮऩू࣌͠ܥྻʹද ࣔ͢ΔαʔϏε ετʔΧʔޚ༻ୡπʔϧ

  7. ར༻ऀͷ੠ ޷͖ͳ͋ͷ່ͱ஥ͷྑ͍ਓ͕෼͔ͬͨ(16ࡀஉੑ) ؾʹͳΔ͋ͷਓ͕Φϑձ͢Δࣄ͕෼͔ͬͨ(16ࡀஉੑ) ޷͖ͳ͋ͷ່͕ࣗ෼Ҏ֎Λ޷͖ͳࣄ͕൑໌(16ࡀஉੑ)

  8. ར༻ऀͷ੠ ޷͖ͳ͋ͷ່ͱ஥ͷྑ͍ਓ͕෼͔ͬͨ(16ࡀஉੑ) ؾʹͳΔ͋ͷਓ͕Φϑձ͢Δࣄ͕෼͔ͬͨ(16ࡀஉੑ) ޷͖ͳ͋ͷ່͕ࣗ෼Ҏ֎Λ޷͖ͳࣄ͕൑໌(16ࡀஉੑ)

  9. #TwitActivity http://twit.yosida95.com Python +Pyramid Nginx uWSGI MySQL + memcache

  10. #TwitActivity http://twit.yosida95.com Python +Pyramid Nginx uWSGI MySQL + memcache

  11. #TwitActivity http://twit.yosida95.com Python +Pyramid Nginx uWSGI MongoDB

  12. What’s MongoDB ? ࠓ࿩୊ͷNoSQL( NoRDB ) υΩϡϝϯτࢦ޲σʔλϕʔε JSONϥΠΫͳBSONͱ͍͏σʔλܗࣜ

  13. Python Meets MongoDB Python͔ΒMongoDBΛѻ͏Ϟδϡʔϧ PyMongo σʔλϕʔεͱͷ઀ଓΛ୲౰ MySQLdb΍ PyMySQLͷΑ͏ͳҐஔ MongoEngine ODM,

    SQLAlchemyͷΑ͏ͳҐஔ σʔλϕʔε઀ଓʹPyMongoΛ࢖༻
  14. σʔλεΩʔϜͷఆٛ 1 #-*- coding: utf-8 -*- 2 3 from mongoengine

    import ( 4 connection, 5 Document, 6 EmbeddedDocument, 7 EmbeddedDocumentField, 8 BooleanField, 9 StringField, 10 EmailField, 11 ImageField, 12 GeoPointField, 13 ListField, 14 ) 15 16 connection('test_db', host='mongo.example.com', port=27017) 17 18 19 class Person(Document): 20 given_name = StringField() 21 email = EmailField() 22 is_male = BooleanField(default=True) 23 photo = ImageField() 24 25 26 class Home(EmbeddedDocument): 27 family_name = StringField() 28 families = ListField(field=EmbeddedDocumentField(Person)) 29 address = GeoPointField() 30 meta = { 31 'indexes': ['family_name', ('family_name', 'address')], 32 }
  15. 1 #-*- coding: utf-8 -*- 2 3 from mongoengine import

    ( 4 connection, 5 Document, 6 EmbeddedDocument, 7 EmbeddedDocumentField, 8 BooleanField, 9 StringField, 10 EmailField, 11 ImageField, 12 GeoPointField, 13 ListField, 14 ) 15 16 connection('test_db', host='mongo.example.com', port=27017) 17 18 19 class Person(Document): 20 given_name = StringField() 21 email = EmailField() 22 is_male = BooleanField(default=True) 23 photo = ImageField() 24 25 26 class Home(EmbeddedDocument): 27 family_name = StringField() 28 families = ListField(field=EmbeddedDocumentField(Person)) 29 address = GeoPointField() 30 meta = { 31 'indexes': ['family_name', ('family_name', 'address')], 32 }
  16. ֤छૢ࡞ 1 #-*- coding: utf-8 -*- 2 3 from models

    import ( 4 Family, 5 ) 6 7 8 # ݕࡧΫΤϦ 9 # Ո଒ʹ໊͕ʮ߉ฏʯͷਓ͕ډΔՈ଒Λݕࡧ 10 kohei = Family.objects.filter(families__given_name=u'߉ฏ') 11 12 # ੏͕ʮ٢ాʯͷՈ଒Λݕࡧ͠ɺ࠷ॳͷσʔλΛyoshidaʹ୅ೖ 13 yoshida = Family.objects.filter(family_name=u'٢ా').first() 14 15 16 # ߋ৽ 17 # ٢ా͔Βླ໦ʹվ੏ 18 yoshida.family_name = u'ླ໦' 19 yoshida.save() 20 21 # ΍ͬͨͶʂՈ଒͕૿͑ͨΑ 22 yoshida.families.append(Person(given_name=u'ϓϩੜͪΌΜ')) 23 yoshida.save() 24 25 # ࡟আ 26 # ϓϩੜͪΌΜΛՈ଒ʹܴ͑ೖΕͨ݁Ռɺ٢ా͞Μ͕ҰՈ΋Ζͱ΋ফ͞Εͨ 27 yoshida.delete()
  17. 1 #-*- coding: utf-8 -*- 2 3 from models import

    ( 4 Family, 5 ) 6 7 8 # ݕࡧΫΤϦ 9 # Ո଒ʹ໊͕ʮ߉ฏʯͷਓ͕ډΔՈ଒Λݕࡧ 10 kohei = Family.objects.filter(families__given_name=u'߉ฏ') 11 12 # ੏͕ʮ٢ాʯͷՈ଒Λݕࡧ͠ɺ࠷ॳͷσʔλΛyoshidaʹ୅ೖ 13 yoshida = Family.objects.filter(family_name=u'٢ా').first() 14 15 16 # ߋ৽ 17 # ٢ా͔Βླ໦ʹվ੏ 18 yoshida.family_name = u'ླ໦' 19 yoshida.save() 20 21 # ΍ͬͨͶʂՈ଒͕૿͑ͨΑ 22 yoshida.families.append(Person(given_name=u'ϓϩੜͪΌΜ')) 23 yoshida.save() 24 25 # ࡟আ 26 # ϓϩੜͪΌΜΛՈ଒ʹܴ͑ೖΕͨ݁Ռɺ ٢ా͞Μ͕ҰՈ΋Ζͱ΋ফ͞Εͨ 27 yoshida.delete()
  18. ϕϯνϚʔΫ Apache Bench uWSGI͕ࢮΜͰϕϯνϚʔΫऔΕͳ ͔ͬͨ httperf Apache Benchͷ݁ՌʹΨοΫϦདྷͯ MySQLͷσʔλফͪ͠Όͬͨ(ũųųƅƁ

  19. ϕϯνϚʔΫ ମײ଎౓ ΊͬͪΌ଎͐͑͑͑͑͑͑͑͑͑͑

  20. MongoDB׵૷ͷײ૝ PyMongo ίωΫγϣϯϓʔϧʹඪ४ରԠ ؾΛ࢖ΘͣʹίωΫγϣϯΛҡ࣋Ͱ͖Δ MongoEngine DjangoͷORMϥΠΫ

  21. MongoDB׵૷ͷײ૝ ૯ධ MongoDB଎͗͢ϫϩλ ద੾ʹΠϯσοΫεுΔͱߋʹૣ͍

  22. ·ͱΊ ΋ͬͱૣ͘MongoDBΛ͍͍ͬͯ͡Ε͹ྑ ͔ͬͨ

  23. ࢀߟࢿྉ MongoEngine User Documentation http://readthedocs.org/docs/mongoengine- odm/en/latest/ mongoDB Manual http://www.mongodb.org/display/DOCS/ Manual

  24. εςϚͦͷ2 Զ

  25. εςϚͦͷ2 ݱࡏɺΞϧόΠτΛ͍͚ͤͯͨͩ͞Δͱ͜Ζ Λ୳͍ͯ͠·͢ɻ ͝ڵຯɺ͓৺ลΓ͕͋Ε͹ɺ΅͘ͱ͓࿩ͤ͞ ͍ͯͩ͘͞ɻ

  26. Thank You For Listening ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠