我正在尝试使用 from_document api 从 python 字典中构建一个 pymodm 文档。我收到错误“ValueError:无法识别的字段名称'prim_key'”
这是我编写的示例代码,以用最少的代码实现这一点。
from pymodm import connect, EmbeddedMongoModel, MongoModel, fields
from pymodm.errors import ValidationError, ConfigurationError
from pymongo.write_concern import WriteConcern
import pprint
from datetime import datetime
class sample_doc(MongoModel):
prim_key = fields.CharField(primary_key=True)
another_field = fields.CharField()
class Meta:
write_concern = WriteConcern(j=True)
connection_alias = 'pymodm-tester'
connect("mongodb://localhost:27017/pymodm-tester", alias="pymodm-tester")
q = {'prim_key' : 'prim_val', "another_field" : "another_filed1" }
sample_doc.from_document(q).save()