You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
files are getting stored in default db even with using switch_db()
Please refer the below code that demostrates the case.
Mongo engine VERSION = 0.10.6
#models.py
from mongoengine import FileField, Document, StringField
from mongoengine import connect, register_connection
connect('ets', alias='default')
register_connection('ets_archive','ets_archive')
class Mediafile(Document):
content_type = StringField(max_length=255, required=True)
file_name = StringField(max_length=1024, required=True)
file_member = FileField( default=None)
from models import Mediafile
from mongoengine.context_managers import switch_db
def save_db():
with switch_db(Mediafile, 'ets_archive') as Mediafile_export_db:
mediafile = Mediafile_export_db()
mediafile.content_type = 'text/plain'
mediafile.file_name = 'new_db.txt'
mediafile.file_member.new_file()
mediafile.file_member.write('new db'.encode("UTF-8"))
mediafile.file_member.close()
mediafile.save()
if __name__ == '__main__':
save_db()
When I run test.py the file is stored to the default database.
Note there Mediafile Document is still stored in the new archive database. Its only the (gridfs)file thats stored in the default database instead of database named 'ets_archive'
The text was updated successfully, but these errors were encountered:
I can not fully express the impact of this bug on my codebases at work. Isolated-database application multi-tenancy is basically impossible if GridFS file storage is utilized through MongoEngine, and it was a hell of a shocker to find files that must be stored separately instead pooled together in the default connection.
files are getting stored in default db even with using switch_db()
Please refer the below code that demostrates the case.
Mongo engine VERSION = 0.10.6
When I run test.py the file is stored to the default database.
Note there Mediafile Document is still stored in the new archive database. Its only the (gridfs)file thats stored in the default database instead of database named 'ets_archive'
The text was updated successfully, but these errors were encountered: