【发布时间】:2023-03-07 18:10:01
【问题描述】:
我正在尝试访问amount。我可以看到数据:
架构:
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' } ] }
invs2.findOne({}, function(err, data){
console.log(data.investors)
})
输出:
[ { id: '1410701852660',
amount: 1.2,
user_id: 'userID',
inv_profit: 0 },
{ id: '1410701858752',
amount: 1.2,
user_id: 'userID',
inv_profit: 0 } ]
但是当我尝试访问data.investors[0].amount 时,我得到了undefined?
即使data.investors.length 也在返回undefined。
invs2 集合中只有一个条目。
【问题讨论】:
-
是的,我已经添加了架构。
标签: json node.js mongodb express mongoose