Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!