skip to Main Content

Here i’m checking with the collection keys, the apikey which im passing in postman it showing invalid credentials. the console value showing null. Dont know where im doing wrong thanks in advance

const fKey = await Key.findOne({
   password: req.params.apikey,
   active: true
});
console.log("fKey....",fKey)

postman :-enter image description here

Database:- enter image description here

2

Answers


  1. You Are Passing params instead of query in code

    const fKey = await Key.findOne({
       password: req.query.apikey,
       active: true
    });
    console.log("fKey....",fKey)
    

    please look at this link for a better understanding.

    Login or Signup to reply.
  2. The problem is not with MongoDB query. It is with request handling. You are using req.params.apikey instead of req.query.apikey.

    const fKey = await Key.findOne({
       password: req.query.apikey,
       active: true
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search