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

85
Views
Express/mongoose devuelve una matriz vacía cuando intenta obtener una solicitud

Estoy tratando de obtener la lista de libros de la base de datos. Inserté los datos en la brújula de mangosta. Solo obtengo una matriz vacía.

 //Model File import mongoose from "mongoose"; const bookSchema = mongoose.Schema({ title: { type: String, required: true, }, description: { type: String, required: true, }, releasedDate: { type: String, required: true, }, }); const Book = mongoose.model("Book", bookSchema); export default Book; //Routes file import express from "express"; import Book from "./bookModel.js"; const router = express.Router(); router.get("/", async (req, res) => { const books = await Book.find({}); res.status(200).json(books); });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

asegúrese de tener datos de libros en db. Si está allí, intente agregar y capturar bloques en su código. Entonces sabrás cuál es el error.

 await Book.find({}) .then((data) =>{ res.send(data) }) .catch((err) =>{ res.send(err) })
about 4 years ago · Juan Pablo Isaza Report

0

Cuando cree su modelo, cambie mongoose.model por un new Schema y declare el atributo _id como:

 var mongoose = require('mongoose'); var Schema = mongoose.Schema; const Book = new Schema({ _id: { type: Schema.ObjectId, auto: true }, // other attributes })

Actualización: si no parece funcionar, intente cambiar _id con otros nombres como bookID o id , ese puede ser el error, lea https://github.com/Automattic/mongoose/issues/1285

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!