Hi I am experimenting with python and mongodb with tornado framework. I am having entry module where user can insert the data of students in academic and sports field. I am using PostMan to verify the code.
def post(self):
print(json_encode(self.body))
db.SearchLog.insert(self.body)
default = 'None'
Date = self.body.get('Date', default)
Reg = self.body.get('Reg', default)
Name = self.body.get('Name', default)
cursor = db.studentDetails.find({'Reg': Reg, 'Name': Name})
value = yield cursor.count()
if value is 0:
db.studentDetails.insert(self.body)
else:
self.write("{"'"success"'": 1, "'"data"'":[")
for document in (yield cursor.to_list(length=100)):
self.write(format(JSONEncoder().encode(document)))
c = 1
if (c < value):
c+=1
value = value - 1
self.write(",")
self.write("]}")
The code works ok. But the problem is with the way the output is displayed.
The output looks like this
{"success": 1, "data":[{"_id": "55acc2205d8882ef8a667d34", "Reg": "11mt", "Name": "Alex", "Total": "98"}]}
{"data": null, "status": "success"}
Because of the presence of two data I could not get the values Name ,Total, Reg.
Is there a way I can send [{"_id": "55acc2205d8882ef8a667d34", "Reg": "11mt", "Name": "Alex", "Total": "98"}]
instead of 'null'.
My output should be like {"data":"[{"_id": "55acc2205d8882ef8a667d34", "Reg": "11mt", "Name": "Alex", "Total": "98"}]" , "status": "success"}
The additional {"data": null, "status": "success"}
I dont know how this is coming.