简体   繁体   中英

Pymongo find() by filter variable return empty

I code it with python 3, mongodb and bottle.

This code return empty document. I check the name which is correctly value.

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

I modified to hard code the name and it can show the result correctly!

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

检查您是否在函数内部的name中获得了一些值,我的直觉是您在该变量中获得了None

The problem might be with the space in the name. Generally strings are url-encoded and the space character is transformed into "+". You might want to url-deencode that and use the result in the db query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM