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

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

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

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

Kohei YOSHIDA

April 07, 2012
Tweet

More Decks by Kohei YOSHIDA

Other Decks in Programming

Transcript

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

    / 0 7 ( S a t . ) ϓ ϩ ά ϥ ϛ ϯ ά ੜ ์ ૹ 1 4 t h
  2. σʔλεΩʔϜͷఆٛ 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 }
  3. 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 }
  4. ֤छૢ࡞ 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()
  5. 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()