'Temporarily switch the database for a document instance.
Only really useful for archiving off data and calling `save()`::
user = User.objects.get(id=user_id)
user.switch_db(\'archive-db\')
user.save()
:param str db_alias: The database alias to use for saving the document
:param bool keep_created: keep self._created value after switching db, else is reset to True
.. seealso::
Use :class:`~mongoengine.context_managers.switch_collection`
if you need to read from another collection'

def switch_db(self, db_alias, keep_created=True):

    with switch_db(self.__class__, db_alias) as cls:
        collection = cls._get_collection()
        db = cls._get_db()
    self._get_collection = (lambda : collection)
    self._get_db = (lambda : db)
    self._collection = collection
    self._created = (True if (not keep_created) else self._created)
    self.__objects = self._qs
    self.__objects._collection_obj = collection
    return self
