1
我想为多个文档做一个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)
'collection'的类型是什么? – Zack
嗨扎克!实际上前面有一些代码,但我并没有在这里粘贴所有的代码。该集合实际上是我的mongodb中的集合。所以这里是我的代码。 dataArray中的= [] 客户端= MongoClient( '本地主机:27017') DB = client.sDB 集合= db.sInsert – xxxSL
有几件事情在这里澄清一下。 'collection.update'嵌套在循环中吗?我不清楚你想要填写什么文件。你能澄清吗? –