Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
Find query returning empty cursor in Python Flask app with Mongodb

I am trying to make a flask app that can support user login request and return data from the mongodb database, after it receives password and username which match with the entry in the database. Although, it is returning me empty value as a result of the find query, prompting null object error at output line, even if the data is present in the database. Also, the code isn't getting inside the 'for loop'.

from flask import Flask, render_template
import pymongo
from flask import jsonify, request
from flask_pymongo import PyMongo
app= Flask(__name__)
app1= Flask(__name__)

app.config['MONGO_DBNAME']= 'VendorDetails'
app.config['MONGO_URL']='mongodb://localhost:27017/VendorDetails'
mongo=PyMongo(app)

@app.route('/getvendorlogin', methods=['POST'])
def getVendorLogin():
    vendor=mongo.db.VendorDetails.VendorDetails
    Username= request.json["Username"]
    Password= request.json["Password"]
    v= vendor.find({'Username':Username},{'Password':Password})
    for record in v:
        Username1= record['Username']
        Password1= record['Password']
        Name1= record['Name']
    output= {"Username":Username1, "Password":Password1, "Name":Name1}
    return jsonify({'result':output})
    if __name__=="__main__":
        app.run(host='0.0.0.0', port=80)

Name of my database is 'VendorDetails' and name of my collection is also 'VendorDetails'. Please suggest me possible way to solve this.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

try to change this line :

 v= vendor.find({'Username':Username},{'Password':Password})

to this one:

 v= vendor.find({"Username": Username, "Password":Password})

let me know if it work.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda