Json 猫鼬罐头';t使用findOne或find方法访问数据

Json 猫鼬罐头';t使用findOne或find方法访问数据,json,node.js,mongodb,express,mongoose,Json,Node.js,Mongodb,Express,Mongoose,我正在尝试访问金额。我可以看到数据: 模式: var schema = mongoose.Schema({ investors : { id : String, amount : Number, user_id : String, inv_profit : Number } }); 命令 invs2.findOne({}, function(err, data){

我正在尝试访问
金额
。我可以看到数据:

模式:

var schema = mongoose.Schema({
    investors : {
        id        : String, 
        amount     : Number,
        user_id      : String,
        inv_profit : Number
    }

});
命令

invs2.findOne({}, function(err, data){

        console.log(data)
})
输出:

{ _id: 54159a1c291df572283fa4de,
  investors: 
   [ { inv_profit: 0,
       user_id: 'userID',
       amount: 1.2,
       id: '1410701852660' },
     { inv_profit: 0,
       user_id: 'userID',
       amount: 1.2,
       id: '1410701858752' } ] }

输出:

[ { id: '1410701852660',
    amount: 1.2,
    user_id: 'userID',
    inv_profit: 0 },
  { id: '1410701858752',
    amount: 1.2,
    user_id: 'userID',
    inv_profit: 0 } ]

但是当我试图访问
数据.investors[0].amount时,我得到的是
未定义的

甚至
data.investors.length
也返回
未定义的


invs2
集合中只有一个条目。

investors
如果是子文档数组,则应在您的架构中将其定义为数组:

var schema = mongoose.Schema({
    investors : [{
        id        : String, 
        amount     : Number,
        user_id      : String,
        inv_profit : Number
    }]
});

是的,我添加了模式。
var schema = mongoose.Schema({
    investors : [{
        id        : String, 
        amount     : Number,
        user_id      : String,
        inv_profit : Number
    }]
});