I have a huge MongoDB database running on mongoengine where the objects have a date. To simplify the work, I want to archive old objects, but keep them somewhere.
I read the documentation and came across switch_db and switch_collection . However, I can neither work nor work.
In both cases, the documentation refers to two use cases.
Like a QuerySet operation:
user = User.objects.get(id=user_id) user.switch_collection('old-users') user.save()
The problem with this is that it only works for a single object. Archiving multiple documents is not possible.
Like context_manager :
with switch_collection(Group, 'group1') as Group: Group(name="hello testdb!").save()
Using this, I canโt even execute the request, getting the following error:
ValidationError (Document:None) (Field is required...
I tried to find a way to archive data using mongoengine, but none of the options worked. Do you have any suggestions?
python mongoengine
liarspocker
source share