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

104
Views
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
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!