I have a problem when I want to include my models with mongoose in nodejs, I create models with such a scheme
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
var Users = new Schema({
idUser : {type:String},
username: {type:String}
});
Users.pre('save', function (next,done) {
notify(this.get('email') + done);
next(new Error('something went wrong'));
});
mongoose.model("Users",Users);
and I save in models folde / schema.js but I don’t know how to call this file in app.js when I try to use this code
var mongoose = require('mongoose')
, models = require('./models/schema.js');
var db = mongoose.connect("mongodb://localhost/vynchat");
var users = mongoose.model("Users");
users.save();
I have an error when I try to run sudo node app.js
throw e;
^
TypeError: Object function model() {
Model.apply(this, arguments);
} has no method 'save'
at Object.<anonymous> (/opt/development/vynapp/app.js:18:7)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
The error model () does not have a save method ... how can I fix this.?
source
share