asyncmongo不返回_id
使用 PyMongo:
import pymongo
conn=pymongo.Connection(host='127.0.0.1',port=27017)
db=conn.cms
db.comments.save({'content':'test', 'user':'admin'})
然后返回:
ObjectId('4ea175b96e955237aa000000')
使用 PyMongo 就可以了。 但是我使用AsyncMongo时无法得到_id响应。
class PoCommentsHandler(BaseClass):
@tornado.web.asynchronous
def post(self):
self.mongo.comments.save({'content':'test', 'user':'admin'}, callback=self._callback)
def _callback(self, response, error):
if error: raise tornado.web.HTTPError(500)
logging.info(response)
self.finish(str(response))
然后返回:
[I 111021 21:25:02 cms:104] [{u'connectionId': 41, u'ok': 1.0, u'err': None, u'n': 0}]
谁能告诉我哪里错了?谢谢
Use PyMongo:
import pymongo
conn=pymongo.Connection(host='127.0.0.1',port=27017)
db=conn.cms
db.comments.save({'content':'test', 'user':'admin'})
Then return:
ObjectId('4ea175b96e955237aa000000')
That all right with PyMongo.
But I cannot get _id in response when I use AsyncMongo.
class PoCommentsHandler(BaseClass):
@tornado.web.asynchronous
def post(self):
self.mongo.comments.save({'content':'test', 'user':'admin'}, callback=self._callback)
def _callback(self, response, error):
if error: raise tornado.web.HTTPError(500)
logging.info(response)
self.finish(str(response))
Then return:
[I 111021 21:25:02 cms:104] [{u'connectionId': 41, u'ok': 1.0, u'err': None, u'n': 0}]
Who can tell me what Wrong? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有什么问题,MongoDB 本身不会返回刚刚插入的文档的 id,pymongo 会为你做这件事。 pymongo API(也在 Tornado IOLoop 上)有一个名为 APyMongo 的异步实现,它的行为应该符合您的预期。
有关此主题的更多信息,请参阅此 Google 群组帖子:http:// groups.google.com/group/python-tornado/browse_thread/thread/9f43f85916156848
There is nothing wrong, the MongoDB itself does not return id of just inserted document, the pymongo does it for you. There is asynchronous implementation of pymongo API (also on Tornado IOLoop) called APyMongo, which should behave as you expected.
More on this topic could be found in this google groups thread: http://groups.google.com/group/python-tornado/browse_thread/thread/9f43f85916156848