Skip to content

Instantly share code, notes, and snippets.

@mountcedar
Last active January 27, 2016 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mountcedar/85e76e70e7cb888ea540 to your computer and use it in GitHub Desktop.
Save mountcedar/85e76e70e7cb888ea540 to your computer and use it in GitHub Desktop.
mongodbを用いたPythonクラスインスタンスのdumpとrestoreとquery検索 ref: http://qiita.com/mountcedar/items/f63006a6d5d5e14acc93
import numpy
import logging
from datetime import datetime
from dbarchive import Base
class Sample(Base):
def __init__(self, maxval=10):
self.base = "hoge"
self.bin = numpy.arange(maxval)
self.created = datetime.now()
print 'create sample instance'
sample01 = Sample(10)
sample01.save()
sample02 = Sample(3)
sample02.save()
for sample in Sample.objects.all():
print 'sample: ', type(sample)
print '\tbase: ', sample.base
print '\tbin: ', sample.bin
print '\tcreated: ', sample.created
sample01.bin = numpy.arange(20)
sample01.save()
for sample in Sample.objects.all():
print 'sample: ', type(sample)
print '\tbase: ', sample.base
print '\tbin: ', sample.bin
print '\tcreated: ', sample.created
print "all task completed"
class Sample(Base):
def __init__(self, maxval=10):
self.base = "hoge"
self.bin = numpy.arange(maxval)
self.created = datetime.now()
print 'create sample instance'
sample01 = Sample(10)
sample01.save()
sample02 = Sample(3)
sample02.save()
for sample in Sample.objects.all():
print 'sample: ', type(sample)
print '\tbase: ', sample.base
print '\tbin: ', sample.bin
print '\tcreated: ', sample.created
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment