首页 > 解决方案 > 获取 TypeError:如果未指定方向,则 key_or_list 必须是列表的实例

问题描述

所以我想在 pymongo 中使用$text方法之后$nearSphere的方法,但为此我收到此错误:TypeError: if no direction is specified, key_or_list must be an instance of list。这里有什么问题?

@app.route('/connect', methods=['GET', 'POST'])
def connect():
    database = mongo.db.mylogin
    mongo.db.mylogin.create_index([("location", pymongo.GEOSPHERE )])
    request_books = database.find({ "location": { "$nearSphere": { "$geometry" : {"type" : "Point",  "coordinates": [session['lang'], session['lat']]}, "$minDistance": 0,  "$maxDistance" : 5000 } } })

    mongo.db.mylogin.create_index( { "name": "text", "description": "text" } )

    search = database.find_one({ "$text": {"$search" : "biology book"}})

    return str(search)

标签: python-3.xmongodbflaskpymongo

解决方案


推荐阅读