我正在使用 node.js 撰寫服務器端代碼,我正在嘗試獲取回傳資料的大小( find() )。這是我的代碼
app.post('/login', function(req, res) {
User.find({
username: req.body.username,
password: req.body.password
}, function(err, users) {
if (err) {
res.status(500).send({
error: "Couldn't find the user"
})
} else {
users.toArray(function(error, n) {
if (n.length == 0) {
console.log("User not found!");
}
});
res.send(users);
}
});
});
uj5u.com熱心網友回復:
.find()回傳一個物件陣列,所以你可以.length對它做
console.log(users.length)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/465847.html
