U
U
uRoot2022-02-12 20:14:36
MongoDB
uRoot, 2022-02-12 20:14:36

Why can't I get a list of categories?

The collection looks like this:
6207ea816a07f918225769.png

Schematic like this:

const categorySchema = new mongoose.Schema({
  title       :   { type : String },
  subCategories:  [
    {
      name: { type: String }
    }
  ]
})


But if I make a request for categories: I await Category.find()

see an empty array. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rag'n' Code Man, 2022-02-12
@iDmitriyWinX

Most likely the name of the collection is different from the name of the collection that Mongoose is looking for.

The call to mongoose.model sets the name of the collection the model is bound to, defaulting to the model name in lowercase plural.
Source: https://stackoverflow.com/questions/14183611/mongo...

It seems to me that in your case the problem is the same, because I do not represent other options.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question