python - Mongoengine-类型错误: Instantiating a document with positional arguments is not supported

标签 python mongodb mongoengine

我已将文档定义创建为 -

class Post(Document):
    title = StringField(required=True, max_length=200)
    content = StringField(required=True)
    author = StringField(required=True, max_length=50)
    published = DateTimeField(default=datetime.datetime.now)

我正在从 json 文件插入数据 --

data_json = json.load(data_file)
post_1 = Post(data_file)
post_1.save()

我收到错误为 -

TypeError: Instantiating a document with positional arguments is not supported. Please use field_name=value keyword arguments.

不支持传递json文件吗?

最佳答案

需要解压字典—— 发布(**数据)

关于python - Mongoengine-类型错误: Instantiating a document with positional arguments is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61485831/

相关文章:

Python删除第一个 View 和第一次单击之间的所有行?

Python正则表达式匹配子字符串

javascript - 如何将 JavaScript 变量传递给 Jinja 标签中的函数

python - mongodb 在聚合时从同一文档的数组中获取唯一值

python - mongoengine 引用字段 mongoengine.errors.ValidationError

python - 保存时提供给 EmbeddedDocumentField 的无效嵌入文档实例

python - 在 Django 项目中使用 request.user.is_authenticated()

python - 归一化二元概率密度函数 - python

javascript - Mongoose如何查看正在生成哪个mongodb查询,数据库没有返回任何内容

mongodb - 所以......这个NoSQL的东西