0
當我去檢查我的數據庫時,我無法看到那裏的studentNamer字段。它就像我從來沒有保存過它。看到明白髮生了什麼。爲什麼它會跳過一個字符串類型的字段,同時保存其他字符串類型的文件?貓鼬不存儲字段
var mongoose = require('mongoose/');
var Schema = mongoose.Schema;
var studentInfoSchema = new Schema({
tty: String,
StudentNamer : String,
id : Number,
tt: String,
numberOfterms : Number
}, {collection: 'studentInfoDatabaseModel'});
var studentInfoDatabaseModel=mongoose.model('studentInfoDatabaseModel', studentInfoSchema);
mongoose.connect('mongodb://localhost/sss');
var db=mongoose.connection;
db
.on('error', console.error.bind(console, 'DB connection error.'))
.once('open', console.log.bind(console, 'DB Connection established.'));
var newItem=new studentInfoDatabaseModel({
tty:"kkk",
studentNamer : "sumiit",
id: 55,
tt: "dfdsffsdaaa",
numberOfterms: 4
});
mongoose.saveToDb=function(){
newItem.save(function(err,result){
if(err){
console.log("there was an err savin");
}
});
}
mongoose.findData=function(){
var posts = db.model('studentInfoDatabaseModel');
posts.find({id : 55}, function(err, calls) {
console.log(err, calls, calls.length); //prints out: null [] 0
var u1= calls[0].id;
var u= calls[0].studentName;
});
}
exports.mongoose=mongoose;