0
我有MongoDB数据库文件其中包含数组奇怪MongoDB的响应格式
{
"_id":ObjectId("588116a66f7d758b144177f7"),
"name":"Michael",
"email":"[email protected]",
"company":"Shift",
"username":"MichaelP",
"password":"$2a$10$unH/7anPylxk1x5zk6/so.YcByZqQoBdFi9IlWnHty2gNouUrt7ea",
"position":"Manager",
"shifts":[
"day",
"day",
null,
"night",
null,
null,
null,
"15"
],
"score":[
null,
"550",
null
],
"__v":0
}
我想在我的网页打印出来shifts[7]
。我是新来的node.js,但我可以打印{{username}}
或{{company}}
罚款shifts[7]
打印'{ '0': '1', '1': '5' }'
我想这是一个简单的解决方案在我的index.js但我似乎无法弄清楚。
我在下面添加我的index.js代码的缩短版本,并感谢您的帮助。
router.get('/hub',ensureAuthenticated, function(req, res, next){
var collection = db.collection('users');
var totalHours= req.user.shifts[7] + '';
var totalhour=0;
res.render('hub', {username: req.user.username,
company: req.user.company,
position: req.user.position,
totalHours: totalhour
});
});
你尝试'VAR totalHours = req.user.shifts [7]。加入( '')'? –
你正在使用嵌套数组错误。嵌套数组应该包含对象。 – Tom
谢谢,@JyothiBabuAraja它说,req.user.shifts [7] .join不是一个函数,我应该单独编写函数吗? – LiveLongCandy51