を作成しながら、私はマングースモデルを作成しようとするMongoDBからデータを取得するためにそれを使用して、私は例外をパッケージからマングースモデル
マイマングースのバージョンを取得していています未定義のプロパティ「ユーザ」を読み取ることができませんガイド.jsonは次のとおりです。"マングース": "4.5.5"
TypeError: Cannot read property 'users' of undefined
が今ここに私のデモコードは次のとおりです。
var mongoose = require("mongoose");
var schema = mongoose.Schema;
var Users = {
_id : {
type : String,
require : true
},
username : {
type : String,
required : true
},
password : {
type : String,
required : true
}
};
var UsersModel = new mongoose.model('users', Users);
var newUser = new UsersModel({"username":"A", "password":"V"});
newUser.save(function(err, result){
if(err){
console.log('>>>>>> Error');
}else{
console.log('>>>>>> ' + JSON.stringify(result, null, 4));
}
});
そして、ここではエラーです:
/home/ankur/Private/Work/ps/node_modules/mongoose/lib/index.js:343
if (!this.modelSchemas[name]) {
^
TypeError: Cannot read property 'users' of undefined
at new Mongoose.model (/home/ankur/Private/Work/ps/node_modules/mongoose/lib/index.js:343:25)
at Object.<anonymous> (/home/ankur/Private/Work/ps/models_mongoose/Users.model.js:24:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3
私の質問はこのコードにあります。余計なことはほとんどありません。スキーマを設定し、そのスキーマで新しいモデルを作成して保存しました。 だから私はものを逃した?
いくつかの意見を控えてください。
私は 'var Users = {...}'は 'var Users = mongoose.Schema({...}) 'であるべきだと思います。それを試しましたか? – mscdex
まだ同じです。 –