TypeError:update()得到关键字参数'upsert'的多个值
我想为多个文档做一个upsert。目前,我尝试'多=真'。它不适合我。TypeError:update()得到关键字参数'upsert'的多个值
我的代码是
dataArray = [] for i in posts_data['posts']['data']:
dataPost = {}
dataPost['post_id'] = i['id']
dataPost['post_message'] = json.dumps(i['message'])
comments_in_posts = graph.get_object(dataPost['post_id'], fields = 'comments')
dataPost['comments_data'] = json.loads(json.dumps(comments_in_posts))
reactions_in_post = graph.get_object(dataPost['post_id'], fields = 'reactions')
dataPost['reactions_data'] = json.loads(json.dumps(reactions_in_post))
getPostReactionCount(dataPost['reactions_data'])
dataArray.append(dataPost)
#insert process
print "before insert"
print "-----------------------------------------------------------"
collection.update({'post_id':dataPost['post_id']}, {'post_message':dataPost['post_message']}, {'comments_data':dataPost['comments_data']},{'reactions_data':dataPost['reactions_data']}, multi=True, upsert=True)
回答:
似乎你正在处理错误的变量 你填充所有结果到
dataArray.append(*dataPost*)
但下次你使用的更新与去年dataPost
collection.update({'post_id':dataPost['post_id']}, {'post_message':dataPost['post_message']}, {'comments_data':dataPost['comments_data']},{'reactions_data':dataPost['reactions_data']}, multi=True, upsert=True)
所以我的意思只是把更新陈述为循环导致你不能只是给该阵列的更新命令 - 它不会理解的结构,也只是FYI有updateMany命令集可用只是更明显地阅读
以上是 TypeError:update()得到关键字参数'upsert'的多个值 的全部内容, 来源链接: utcz.com/qa/265955.html