【问题标题】:mongoengine access gridfs in multiple databasesmongoengine访问多个数据库中的gridfs
【发布时间】:2016-12-24 17:25:37
【问题描述】:

对于大多数字段,我一直使用db_alias 访问我的其他数据库。但是,对于带有FileField()ImageField() 的模型,我无法访问其他数据库中的文件。 db_alias 是否没有正确链接到其他数据库中的 fs.files 和 fs.chunks?

class File(db.Document):
     file = db.ImageField()
     meta = {"db_alias": "OtherDB"}

for i in File.objects.all():
     print i.file          # Shows '<ImageGridFsProxy: (no file)>'
     print i.file.length   # Shows 'AttributeError'

【问题讨论】:

    标签: mongoengine gridfs


    【解决方案1】:

    在 github 上搜索 mongoengine 问题报告时,我遇到了一个提示。基本上,对于FileField()ImageField(),必须将 db_alias 直接放入字段中。例如,这有效:

    class File(db.Document):
         file = db.ImageField(db_alias="OtherDB")
    

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      相关资源
      最近更新 更多