Answer the question
In order to leave comments, you need to log in
How to extract a parameter from a model object?
Good day, I can’t extract name from owner into a variable, and then display the variable in the console.
Model:
const { Schema, model } = require('mongoose');
const scheduleSchema = new Schema({
owner: {
name: {
type: String,
required: true
},
password: String
},
schedule: [{
dow: {
type: String,
required: true
},
lessons: [{
start: String,
name: String
}]
}]
});
module.exports = model('Schedule', scheduleSchema);
var express = require("express");
var router = express.Router();
var Schedule = require("../models/schedule");
router.post("/", async function(req, res, next) {
const isPasswordConfirmed = req.body.password === req.body.password_repeat;
if (req.body.username && isPasswordConfirmed) {
var info = await Schedule.find({ "owner.name": [] }); // <--- ВОТ В ЭТОЙ ШТУКЕ ВСЯ МОЯ ПРОБЛЕМА
console.log(info)
// Schedule.find()
// // .sort([
// // ['owner.name']
// // ])
// .exec(function(err, list_name) {
// if (err) { return next(err); }
// console.log(list_name);
// })
const newUser = new Schedule({
owner: {
name: req.body.username,
password: req.body.password
}
});
await newUser.save();
res.redirect(`/user/${newUser.owner.name}`);
} else {
console.log('Отсечка')
}
res.render("register", { error: { message: "Пароли не совпадают" } });
});
router.get("/", function(req, res, next) {
res.render("register");
});
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