Answer the question
In order to leave comments, you need to log in
Why does it throw an error User.every is not a function?
I want to extract the username from this object into the usernameActive variable :
{ owner: { name: 'Jack', password: '12345' },
_id: 605f27e660d71e175c928c68,
__v: 0 }
var express = require('express');
var router = express.Router();
var Schedule = require("../models/schedule");
var ChatList = require("../models/chatList");
var usernameActive;
router.param("owner", async function(req, res, next, owner) {
try {
const User = await Schedule.findOne({ "owner.name": owner });
User.every(function(keyUsername) {
usernameActive = keyUsername;
});
console.log(usernameActive);
if (User) {
req.owner = User;
next();
} else {
next(createError(403));
}
} catch (error) {
console.log('error')
next(error);
}
});
/* GET users listing. */
router.get("/:owner", function(req, res, next) {
res.render("user", { user: req.owner });
});
module.exports = router;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question