MongoEngine 不保存没有错误消息的字段
MongoEngine does not save field with no error message
我使用 MongoEngine 在 MongoDB 中设置了以下模型。
class Category(Document):
normed_name = StringField(),
name = StringField(),
path = StringField(),
最初模型不同,我确实导入了一些文件,但我删除了所有旧数据库并将模型更改为上述模型。
当我然后 运行 以下 python 脚本时:
import model
from mongoengine import connect
uri = 'mongodb://<user>:<pass>@<me>.mlab.com:<port>/cost_database'
connect('cost_database', host = uri)
test = model.Category()
test.name = 'test'
print(test.name)
test.save(validate=False)
脚本输出,
test
但在数据库中创建了以下文件:
{
"_id": {
"$oid": "5a61e64dc645177b50d0d656"
}
}
知道为什么名字没有保存吗?
我的错误是在字段定义后添加了逗号。
class Category(Document):
normed_name = StringField()
name = StringField()
path = StringField()
以上解决了问题。
不幸的是,我再也没有时间意识到这一点。 :(
我使用 MongoEngine 在 MongoDB 中设置了以下模型。
class Category(Document):
normed_name = StringField(),
name = StringField(),
path = StringField(),
最初模型不同,我确实导入了一些文件,但我删除了所有旧数据库并将模型更改为上述模型。
当我然后 运行 以下 python 脚本时:
import model
from mongoengine import connect
uri = 'mongodb://<user>:<pass>@<me>.mlab.com:<port>/cost_database'
connect('cost_database', host = uri)
test = model.Category()
test.name = 'test'
print(test.name)
test.save(validate=False)
脚本输出,
test
但在数据库中创建了以下文件:
{
"_id": {
"$oid": "5a61e64dc645177b50d0d656"
}
}
知道为什么名字没有保存吗?
我的错误是在字段定义后添加了逗号。
class Category(Document):
normed_name = StringField()
name = StringField()
path = StringField()
以上解决了问题。
不幸的是,我再也没有时间意识到这一点。 :(