python - Archive old data in mongoengine -
python - Archive old data in mongoengine -
i have huge mongodb database powered mongoengine objects have date. create work easier, want archive old objects maintain them somewhere.
i've been reading documentation , came across switch_db
, switch_collection
. however, can't create either work.
for both cases, documentation references 2 usage scenarios.
as queryset
operation:
user = user.objects.get(id=user_id) user.switch_collection('old-users') user.save()
the problem works individual object. not possible batch archive multiple documents.
as context_manager
:
with switch_collection(group, 'group1') group: group(name="hello testdb!").save() # saves in group1 collection
using can't create query, getting next error:
validationerror (document:none) (field required...
i've tried searching way archive info mongoengine, none of options seem work. have suggestion?
if have access mongodb instance itself, why not run query straight against that, instead of jumping thru hoops of mongoengine?
you can rename current users
collection users-old
using command:
http://docs.mongodb.org/manual/reference/command/renamecollection/
and run simple script re-create newer values on new users
collection
python mongoengine
Comments
Post a Comment