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
why can't select the data with the condition using MongoDB

I can use this code to get all the data from MongoDB.

import nextConnect from 'next-connect';
import middleware from '../database';

const handler = nextConnect();

handler.use(middleware);

handler.get(async (req, res) => {

    let doc = [];

    await req.db.collection("mountain").find().forEach(element => {
        doc.push(element);
    });
    console.log(doc);
    res.json(doc);
});

export default handler;

But I can't get the data with the condition.

import nextConnect from 'next-connect';
import middleware from '../database';

const handler = nextConnect();

handler.use(middleware);

handler.get(async (req, res) => {

    let doc = await req.db.collection("mountain").find({ name: "Lion Rock" })
    console.log(doc);
    res.json(doc);
});

export default handler;

The data in my MongoDB is like this:

enter image description here

Does anyone know where is the problem? Thank you!

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