gpt4 book ai didi

python - MongoKit 无模式

转载 作者:太空宇宙 更新时间:2023-11-03 19:28:34 25 4
gpt4 key购买 nike

我有一个如下所示的对象:

@connection.register
class User(Document):
__collection__ = 'users'
__database__ = 'crucible_projects'
use_schemaless = True
structure = {
'name': unicode,
'password': unicode,
'last_name': unicode,
'first_name': unicode,
'email': unicode,
'last_login': datetime.datetime,
}
use_dot_notation = True
def __repr__(self):
return '<User %r>' % (self.name)

我在手动输入的数据库中已有一个用户,该用户没有名字和姓氏字段。问题是当我尝试运行这个时

def login_user(user):
found_attribute = connection.User.find_one({'name':user})
found_attribute.last_login = datetime.datetime.utcnow()
found_attribute.save()

我明白了

>>> import db_users
>>> db_users.login_user('admin')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "db_users.py", line 91, in login_user
found_attribute.save()
File "c:\Python27\lib\site-packages\mongokit-0.7-py2.7.egg\mongokit\document.py", line 394, in save
self.validate(auto_migrate=False)
File "c:\Python27\lib\site-packages\mongokit-0.7-py2.7.egg\mongokit\document.py", line 243, in validate
super(Document, self).validate()
File "c:\Python27\lib\site-packages\mongokit-0.7-py2.7.egg\mongokit\schema_document.py", line 353, in validate
self._validate_doc(self, self.structure)
File "c:\Python27\lib\site-packages\mongokit-0.7-py2.7.egg\mongokit\schema_document.py", line 569, in _validate_doc
"missed fields : %s" % struct_doc_diff )
File "c:\Python27\lib\site-packages\mongokit-0.7-py2.7.egg\mongokit\schema_document.py", line 524, in _raise_exception

raise exception(message)
mongokit.schema_document.StructureError: missed fields : ['first_name', 'last_name']

我想要一些不具有结构中所有字段的对象。我做错了什么?

添加了答案。

最佳答案

这是一个错误。 v0.7.1 已修复

Changelog :

* change MongokitMasterSlaveConnection to MasterSlaveConnection for consistency
* fix #57 -- support pymongo > 1.9 in grid.py
* fix #45 -- remove automatique index creation
* fix #43 -- slicing a cursor should return a mongokit document, not dict
* Dont try to convert None struct to json (patch from @mLewisLogic thanks !)
* fix schemaless issue (thanks to Mihai Pocorschi for reporting it)

关于python - MongoKit 无模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7158589/

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