我想db.collection.createIndex在我的 mongodb 文档中使用方法,但我得到了NameError: name 'db' is not defined。我如何在 flask_pymnogo 中使用这种方法?
请帮忙
这是代码
@app.route('/insert')
def inserting_data():
database = mongo.db.mylogin
user_col = database.find({ "location": { "$nearSphere": { "$geometry": {"type": "Point", "coordinates": [21.0955, 81.0375]}, "$maxDistance":5000 } } })
db.database.createIndex( { "location": "2dsphere" } )
return list(user_col)