Pymongo find()由filter变量返回空

时间:2016-05-03 06:40:53

标签: python pymongo bottle

我用python 3,mongodb和bottle编码。

此代码返回空文档。我检查name哪个是正确值。

@bottle.route('/test1/<name>', method='GET')
def test_detail(name):
    result = dbcoll.find({"student": name})
    return template('detail',name=result)

我修改了name的硬编码,它可以正确显示结果!

@bottle.route('/test1/<name>', method='GET')
def test_detail(name):
    name = "peter chan"
    result = dbcoll.find({"student": name})
    return template('detail',name=result)

2 个答案:

答案 0 :(得分:0)

检查你是否在mysql> SHOW STATUS LIKE 'key%' +------------------------+-------------+ | Variable_name | Value | +------------------------+-------------+ | Key_blocks_not_flushed | 0 | | Key_blocks_unused | 275029 | | Key_blocks_used | 3316428 | | Key_read_requests | 11459264178 | | Key_reads | 3385967 | | Key_write_requests | 91281692 | | Key_writes | 27930218 | +------------------------+-------------+ 内部功能中获得了一些价值,我的直觉是你在该变量中得到name

答案 1 :(得分:0)

问题可能在于名称中的空格。通常字符串是url编码的,空格字符转换为&#34; +&#34;。您可能希望对其进行url-deencode并在db查询中使用结果。