Am working on python and mongodb. I am trying to find names from a table with the by matching them with their phone no.s. The phone number is in a list which i created by getting the numbers from another table. Its working fine but I am getting the output being printed twice.
phone = ["9585507882","9542158582"]
datum = []
for i in phone:
cursor = db.name.find({"phone": i},{"_id": False})
value = yield cursor.count()
if value is 0:
pass
else:
result = []
for document in (yield cursor.to_list(length=100)):
datum.append(document)
print(datum)
self.write(bson.json_util.dumps({"result": datum}))
My output is
{"result": [{"phone": "9585507882", "name": "Sanjay"}]}{"result": [{"phone": "9585509882", "name": "Sanjay"}, {"phone": "9542158582", "name": "Joe"}]}
can anyone help me out with this problem.
yieldused this way. What's this about?motor