我对python和mongodb相当陌生,我已经面临一个问题。
我正在尝试使用mongodb作为数据源将nodejs后端restapi“转换”为烧瓶。
使用flask文档,我能够配置我的应用程序以连接到本地mongod。
我可以users
像这样从集合中获取价值
def getUser():
usr = Users.objects(email="[email protected]")
return {
"user": usr,
}
通过邮递员调用API时返回以下JSON
{
"user": [
{
"__v": 0,
"_id": {
"$oid": "5da86dc651eac87d2a82e2e2"
},
"createdAt": {
"$date": 1571319238918
},
"email": "[email protected]",
"password": "$2b$10$hoH57R5GL1MrwqpuW4yEJ.wwLlyNgyfxQm2Mxb19wioYTPPsU9z7y",
"profil": {
"_id": {
"$oid": "5da86dc651eac87d2a82e2e3"
},
"checked": false,
"clapList": [],
"followerList": [],
"followingList": [],
"playpoint": 0
},
"updatedAt": {
"$date": 1571319477959
}
}
]
}
如您所见,我有一个包含一个用户的数组。当我尝试仅获取一个对象时,如下所示:
def getUser():
usr = Users.objects(email="[email protected]").first()
return {
"user": usr,
}
我在Postman中返回了500状态,并且在调试控制台中出现以下错误: mongoengine.errors.FieldDoesNotExist: The fields "{'__v'}" do not exist on the document "Users"
这是我的用户模型
import mongoengine as me
class Users(me.Document):
phone = me.StringField()
email = me.StringField()
password = me.StringField()
accountType = me.StringField()
createdAt = me.DateTimeField()
updatedAt = me.DateTimeField()
profil = me.EmbeddedDocumentField(Profil)
我已经尝试将添加__v
为InfField()
,但是仍然有相同的错误。
那是什么__v
呢,我应当尝试做从头开始一个新的数据库?
附加信息:
所以我添加了一个meta属性,现在我可以使用该类了
meta = {
'strict': False,
}
我真的还不知道那里发生了什么,但是如果可行的话,我什么也没碰
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句