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

102
Views
Finding documents that fit json input in mongodb

I'm trying to do a write statement that finds all the documents that fit the JSON data fed through a form. Here's an example of what the JSON looks like. I created a document on the database that has these exact same info and I still get nothing in return.

{
  type: 'Diamond',
  weight: '1',
  size: '1',
  color: 'Red',
  origin: 'Mexico',
  clarity: 'Translucent',
  shape: 'Pear'
}

and here's my code:

module.exports.renderSpecifics = async (req, res) => {
    const query = await req.query
    for (let key in query) {
        console.log(typeof key)
        if (Number(query[key])) {
            query[key] = parseInt(query[key])

        }
    }
    console.log(query)
    const campgrounds = await Campground.findMany({ query })
    console.log(campgrounds)

    res.render('campgrounds/index', { campgrounds })
}

the JSON after the for loop is the folllowing:

{
  type: 'Diamond',
  weight: 1,
  size: 1,
  color: 'Red',
  origin: 'Mexico',
  clarity: 'Translucent',
  shape: 'Pear'
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

first you should create a model with mongoose Schema. The 'Model.findOne()' method should solve your problem.

Method Docs: https://mongoosejs.com/docs/api.html#model_Model.findOne

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