javascript - Cannot read property 'users' of undefined -
I am new to mongodbi and I have database of users. I am trying to make a user click on the buttons of their favorite shoes and update this database. My schema is as follows:
var mongoose = is required ('magos'); Var bcrypt = requirement ('bipet-nodes'); // Define the schema for our user model var userSchema = mongoose.Schema ({local: {email: string, password: string,},}); // methods ====================== A hash userSchema.methods.generateHash = function (password) {generated bcrypt.hashSync (password, bcrypt.GenSaltSync ( 8), tap); }; // Check if the password is valid userSchema.methods.validPassword = function (password) {return bcrypt.compareSync (password, this.local.password); }; // Create a model for users and expose it to our app module. Exports = Mongosse Model ('user', user schema);
DB function posting:
exports.addToFavs = function (req, res) {var size_result = req.query.size; Var brandToFind = req.query.brandToFind; Req.db.users.update ({email: req.user.email}, {$ set: favorite show [{name: brandToFind, size: size_result}]}); / *, Function (error, favorite shop) {if (error) coming back (error); Return (! Favorites) if returned (new error ('unsuccessful saving')); * / Console.info ('id =% s has been added with% s, brandToFind, size_result); Res.redirect ('/ favorites'); //})};
HTML button:
& lt; Form action = "/ results" method = "post" & gt; & Lt; Center & gt; & Lt; Button & gt; Save to Favorites & lt; / Button & gt; & Lt; / Center & gt; & Lt; / Form & gt;
The correct path:
app post ('/ results', search .zip; adtOfaves);
I am really confused about how it works ... Somehow it can not be read by the DB table "Users" (Confirmed through the console that This is what the table is called) So it is trying to work but it is not working ...
Comments
Post a Comment