Answer the question
In order to leave comments, you need to log in
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);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question