L
L
lodas2020-11-23 21:46:53
MongoDB
lodas, 2020-11-23 21:46:53

Why is mongoose not returning the result of the model?

Hello everyone, in the nuxt controller I'm trying to work with the MongoDB database using mongoose
, the connection code is this:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

    try {
        await mongoose.connect("mongodb://127.0.0.1:27017/dbBlog", {
            useNewUrlParser: true,
            useUnifiedTopology: true,
            useFindAndModify: false,
            useCreateIndex: true
        });
    } catch (error) {
        handleError(error);
    }

    const db = mongoose.connection;
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', function() {
        console.log('MongoDB connected...');
    });

    const userScheme = new Schema({
        name: String,
    });

    const User = mongoose.model("Users", userScheme);
    
    User.find({}, function (err, data) {
        console.log(err, data);
    });

in the console when outputting User.find() for some reason null [] is displayed - emptiness. although there are definitely records in this database (I attach a screen). Can you please tell me why mongoose does not return the result from the table?
5fbc036ab6efc699892763.png

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