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

180
Views
obtener datos por id de la recopilación de datos de mongoDb atlas

Estoy tratando de obtener datos usando id pero siempre obtengo un error interno 500 . Sería de gran ayuda si alguien ayudara a encontrar qué error he cometido para get la solicitud. Realicé una solicitud de publicación con éxito y almacené datos en la colección MyDatabase de MongoDb Atlas

Aquí está mi código:

 app.get("/student/:id", function (req, res) { db.collection("MyDatabase").findOne(req.params.id, function (err, docs) { if (err) { handleError(res, err.message, "Failed to get student record."); } else { res.status(200).json(docs); } }); });

Yo he tratado :

 var ObjectId = require("mongodb").ObjectID; db.collection("MyDatabase").findOne( { _id: new ObjectId(id) }

pero sigue sin funcionar

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto funciona para mí:

 app.get("/student/:id", function (req, res) { const id = req.params.id; var o_id = new mongoDB.ObjectID(id); db.collection("MyDatabase").findOne({ _id: o_id }, function (err, docs) { if (err) { handleError(res, err.message, "Failed to get student data."); } else { res.status(200).json(docs); } }); });
over 4 years ago · Santiago Trujillo 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!