0

my app.js contains the following code which I am trying to execute.

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/node_001');

var db = mongoose.connection;
//Bind connection to error event (to get notification of connection errors)
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
  // we're connected!
  console.log("Connected Successfully...");
});

var userSchema = new mongoose.Schema
({
    _id: Number,
    email: String,
    pass: String
});

var User = mongoose.model('user', 'userSchema');

// get all the users
User.find({}, function(err, users) {
  if (err) throw err;

  // object of all the users
  console.log(users);
});

mongoose.connection.close();

It throws an error message (MissingSchemaError: Schema hasn't been registered for model "User".) Please help to identify my mistake.

0 Answers0