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

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

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 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