как включить внешние модели в мангуст?

у меня проблема, когда я хочу включить свои модели с мангустом в nodejs, я создаю модели с такой схемой

var mongoose = require('mongoose')
  , Schema = mongoose.Schema;

var Users = new Schema({
    idUser  : {type:String},
    username: {type:String}
});

// middleware
Users.pre('save', function (next,done) {
  notify(this.get('email') + done);
  // something goes wrong
  next(new Error('something went wrong'));
});

//registered on mongoose models
mongoose.model("Users",Users);

и сохраняю в папке models/schema.js но я не знаю, как вызвать этот файл в app.js, когда я пытаюсь использовать этот код

var mongoose = require('mongoose')
  , models = require('./models/schema.js');

//mongoose configurationfor database;
var db = mongoose.connect("mongodb://localhost/vynchat");
var users = mongoose.model("Users");
users.save();

, у меня возникает ошибка при попытке запустить sudo node app.js

throw e; // process.nextTick error, or 'error' event on first tick
              ^
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)

модель ошибки ( ) не имеет метода save... как я могу это исправить..?

9
задан viyancs 1 March 2012 в 21:46
поделиться