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

199
Views
Encoded query not working when using it to find data

I am encoding a query with encodeURIComponent and then using it in backend but it isn't working.

Db : mongodb Odm : mongoose

What i do is :

encodeURIComponent("{ name: { $regex: 'da', $options: 'i' }}")
which is %7B%20name%3A%20%7B%20%24regex%3A%20'da'%2C%20%24options%3A%20'i'%20%7D%7D

I send it like this:

/api/nft/search?q=%7B%20name%3A%20%7B%20%24regex%3A%20%27da%27%2C%20%24options%3A%20%27i%27%20%7D%7D

I use it like this :

exports.searchNftByName = (req, res) => {
  console.log(req.query.q);
  Nft.find(req.query.q).exec((err, nft) => {
    if (err || !nft) {
      return res.status(400).json({
        status: 'fail',
        message: 'NFT not found!',
      });
    }
    return res.status(200).json({
      status: 'success',
      message: 'We found something',
      nft,
    });
  });
};

console.log(req.query.q); out is { name: { $regex: 'da', $options: 'i' }}

When i copy it from console and use it directly to find the data it works.

about 4 years ago · Juan Pablo Isaza
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!