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'嵌套在循環中嗎?我不清楚你想要填寫什麼文件。你能澄清嗎? –