I
I
Incold2020-06-11 00:51:05
MongoDB
Incold, 2020-06-11 00:51:05

Why does Mongoose find() return an empty array?

Hello! I recently started studying the Node.js + MongoDB (Mongoose) stack and ran into a problem, the find method always returns an empty array, although there is data in the collection

const mongoose = require("mongoose");
const schemas = require('./dbSchemas');
const enviroments = require('./enviroment');

module.exports = {
  getMenu(res) {
    //dbUrl = "mongodb://localhost:27017/Pizza"
    mongoose.connect(enviroments.dbUrl, { useNewUrlParser: true,  useUnifiedTopology: true });
    const Menu = mongoose.model('menu', schemas.menuSchema);

    Menu.find({}).exec() // callback также, не работает
      .then(menu => {
          console.log(menu) // здесь выводит пустой массив
          res.send(menu);
        })
        .catch(err => {
          res.send(err);
        })
        .finally(() => {
          mongoose.disconnect();
        })
  }
}


Scheme:
menuSchema: new Schema({
    pizzaName: {
      type: String,
      required: true
    },
    ingridients: {
      type: [String],
      required: true
    },
    price:  {
      type: Number,
      required: true,
    }
  })

And here is what the mongoDB console outputs:
5ee154921c51b966609963.png
The only point is that I entered all the data manually through the console, if this somehow affects mongoose, then how to fix it?
Why does an empty array always come if there is data in the collection?
Thanks in advance for any help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question