猫鼬不存储字段

时间:2015-11-01 05:28:26

标签: node.js mongodb

当我去检查我的数据库时,我无法在那里看到studentNamer字段。它就像我永远不会保存它。看到了解正在发生的事情。为什么它会跳过一个string类型的字段,同时保存string类型的其他文件?

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;

1 个答案:

答案 0 :(得分:1)

您在架构中将其声明为StudentNamer(请注意“ S ”),但您尝试将其另存为studentNamer : "sumiit"(请注意“ s “),所以只需将其更改为:

var studentInfoSchema = new Schema({
    tty: String,
    studentNamer :  String,
    id  : Number,
    tt: String,
    numberOfterms  : Number
}, {collection: 'studentInfoDatabaseModel'});