U
U
uRoot2021-08-28 21:32:29
MongoDB
uRoot, 2021-08-28 21:32:29

Why is Node returning an empty array from Mongo's collection?

There is a model:

import mongoose from "mongoose";

const Posts = new mongoose.Schema({
  title: {type: String, required: true},
  description: {type: String, required: true},
  text: {type: String, required: true},
  image: {type: String}
})

export default mongoose.model("Posts", Posts)

There is a service:
import Posts from '../models/post'

class PostService {
  async getAll() {
    const post = await Posts.find() // вот тут уже пустой массив приходит: []
    return post
  }
}
export default new PostService()


DB screen
612a801b06438127507869.png


Screenshot of request/response from Postman
612a80e4e4f0c803052403.png


Tell me how to fix it and where to dig at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
uRoot, 2021-08-29
@uroot

Found what was the problem... forgot to change the name of the database in the config

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question