Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda