Browse Source

tornado: _id => id

INADA Naoki 11 years ago
parent
commit
cc6a398a46
1 changed files with 5 additions and 2 deletions
  1. 5 2
      tornado/server.py

+ 5 - 2
tornado/server.py

@@ -1,5 +1,6 @@
 import random
 import sys
+from bson import ObjectId
 
 import json
 import motor
@@ -41,15 +42,17 @@ class QueryTestHandler(BaseHandler):
 
         if queries == 0:
             random_id = random.randint(1, 10000)
-            world = yield motor.Op(db.World.find_one,{"_id": random_id}, fields={"_id": 1, "randomNumber": 1})
+            world = yield motor.Op(db.world.find_one, random_id)
             # Get first postion on arguments, and so first postion in mongo return
+            world['id'] = world.pop('_id')
             response = json.dumps(world)
         else:
             worlds = []
             for i in xrange(int(queries)):
                 random_id = random.randint(1, 10000)
-                world = yield motor.Op(db.World.find_one,{"_id": random_id}, fields={"_id": 1, "randomNumber": 1})
+                world = yield motor.Op(db.world.find_one, random_id)
                 # Get first postion on arguments, and so first postion in mongo return
+                world['id'] = world.pop('_id')
                 worlds.append(world)
             response = json.dumps(worlds)
         self.set_header("Content-Type", "application/json; charset=UTF-8")