Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将嵌套字段添加到结构时MongoKit中的KeyError_Python_Django_Mongodb_Mongokit - Fatal编程技术网

Python 将嵌套字段添加到结构时MongoKit中的KeyError

Python 将嵌套字段添加到结构时MongoKit中的KeyError,python,django,mongodb,mongokit,Python,Django,Mongodb,Mongokit,我的结构如下: structure = { 'firstname': basestring, 'lastname': basestring, 'genres': [basestring], 'address': [ {'number': basestring, 'street': basestring, 'town': basestring} ], 'phone': [ {'type': basestring, 'n

我的结构如下:

structure = {
    'firstname': basestring,
    'lastname': basestring,
    'genres': [basestring],
    'address': [
        {'number': basestring, 'street': basestring, 'town': basestring}
    ],
    'phone': [
        {'type': basestring, 'number': basestring}
    ],
}
我有一个小的助手方法来迭代游标以返回python dict,如下所示:

def to_django_context(cursor):
    records = []
    for r in cursor:
        records.append(r.to_json_type())
    return records
在我想向结构中添加另一个嵌套字段之前,这一切正常,如下所示:

structure = {
    'firstname': basestring,
    'lastname': basestring,
    'genres': [basestring],
    'address': [
        {'number': basestring, 'street': basestring, 'town': basestring}
    ],
    'phone': [
        {'type': basestring, 'number': basestring}
    ],
    'title': [{'TEST_FIELD': basestring}],
}
在这一点上,我的游标迭代器失败,出现了一个keyrerror。如果我删除集合中的所有文档,它将正常工作。那么,这是否意味着每次更改文档结构对象时,都必须从本质上删除集合

干杯,
F

更具体地说,这是光标中的r:行失败的键错误消息是什么?