Mongoose Schema.Types.Mixed不起作用

时间:2014-06-27 01:26:27

标签: mongoose

  1. 使用mongoose schema.types.Mixed读取现有集合时无法识别键/值对,控制台只显示“_id”,但在尝试访问其他键/值时,我得到一个未定义的

    var UserSchema1 = new mongoose.Schema({ key: {}});
    var UserSchema2 = new mongoose.Schema({
    userID: Number,
    userName: String,
    password: String});
    var User = mongoose.model('user', UserSchema1,'info' );
    router.get('/', function(req, res) {
    User.find({}, function(err, docs) {
    var s = docs;
    console.log(s[0].userName);
    console.log(s[0]._id);
    res.render('userinfo', {users : docs});
    });
    });
    ---- OUTPUT ----
                                    **UserSchema1**         -     **UserSchema2**
     console.log(s[0].userName);       undefined                  mongo
    console.log(s[0]._id);             241245j23j6l26l6       afa88asf8989asfa
    
    --jade.js--
    ul
        each user in users
      li #{user._id}
      li #{user['userName']}
    
     Shows only  li with the _id 
     but it creates empty  li  supposedly for user.name  
    

2 个答案:

答案 0 :(得分:0)

要使用此数据类型,您不能{},而是schema.types.Mixed。所以猫鼬是一个待拯救的对象。

答案 1 :(得分:0)

为了工作,您必须使用Schema.Types.Mixed(每个单词大写),您可以看到here(搜索Schema.Types.Mixed)并且没有花括号{}

相关问题