这是我的代码段,用于检查多余的questionText,并将其从集合中删除。现在我要检查不区分大小写 外汇:CHINA,中国检查是否有重复,从中删除一个
我的代码:
myclient = pymongo.MongoClient("mongodb://localhost:3000/")
print("Connection Successful")
mydb = myclient["demo"]
mycol2 = mydb["questions"]
map = Code("function(){ if(this.questionText){emit(this.questionText,1);}}")
reduce = Code("function(key,values) {"
"return Array.sum(values);"
"}")
res = mycol2.map_reduce(map,reduce,"my_results");
response = []
for doc in res.find():
if(doc['value'] > 1):
count = int(doc['value']) - 1
docs = mycol2.find({"questionText":doc['_id']},{'_id':1}).limit(count)
for i in docs:
response.append(i['_id'])
#mycol2.remove({"_id": {"$in": response}})
print(response)