gpt4 book ai didi

python - 为什么我从 mongoalchemy 得到 ExtraValueException?

转载 作者:可可西里 更新时间:2023-11-01 09:37:48 25 4
gpt4 key购买 nike

这是我的类(class):

class Presentation(db.Document):
title = db.StringField(max_length=120, required=True)
author = db.StringField (required=True)
pages = db.DocumentField(Page, required=False)
tags = db.StringField(max_length=120, required=False)
id = db.IntField(required=True)
currentPage = db.IntField()
def __str__(self):
return 'Title:%s author:%s id:%d currentPage:%d' % ( self.title, self.author,self.id,self.currentPage)

当我从 mongo shell 使用它时,一切似乎都很好:

db.Presentation.find({id:2})

{ "_id" : ObjectId("4e9cdddd0ad5c97ee6000000"), 
"author" : "admin", "currentPage" : 3, "id" : 2,
"pages" : { "content" : "", "pagenum" : 0 }, "title" : "dd" }

但是当我使用 MongoAlchemy 时,

p = query.filter(Presentation.id==2).first()

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.7-intel/egg/mongoalchemy/query.py", line 136, in first
File "build/bdist.macosx-10.7-intel/egg/mongoalchemy/query.py", line 388, in next
File "build/bdist.macosx-10.7-intel/egg/mongoalchemy/document.py", line 318, in unwrap
File "build/bdist.macosx-10.7-intel/egg/mongoalchemy/document.py", line 152, in __init__

mongoalchemy.exceptions.ExtraValueException: currentPage

最佳答案

对于任何其他有 ExtraValueException 的人,如果您在类定义中放置一个额外的逗号,您也会看到此错误。例如,如果您有:

...
pages = db.DocumentField(Page, required=False),
tags = db.StringField(max_length=120, required=False)
...

尝试使用页面或标签会产生 ExtraValueException。

这是我在痛苦中学到的。

关于python - 为什么我从 mongoalchemy 得到 ExtraValueException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7801984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com