mern

How to display data coming from mongodb to reactjs after clicking the button?

老子叫甜甜 提交于 2021-02-10 15:31:28
问题 I am making react project using express.js, mongodb, react.js, and node.js. and trying to fetch data from backend api which is running on port 5000. When I check the api using postman , it is working. And the data is showing in the browser's console. Also, when I press Get button as given in the code below, it doesn't work on the browser. But I'm able to see the array data in the browser's console. <Button onClick={()=><li>{employeeItem}</li>}>Get</Button> Here is my full code: import React,

I want my pre('save') mongoose function to operate only once

谁说胖子不能爱 提交于 2021-02-05 10:30:49
问题 I do not know if the exact request in title is possible, but if not; i would really appreciate an alternate solution. I have this pre save method of mongoose ownerSchema.pre("save", function(next) { const owner = this; bcrypt.genSalt(10, function(err, salt) { bcrypt.hash(owner.password, salt, function(err, hash) { // Store hash in your password DB. owner.password = hash; next(); }); }); }); When i save new user(owner) a hash is created successfully and all is good> The problem occurs when i

I want my pre('save') mongoose function to operate only once

半城伤御伤魂 提交于 2021-02-05 10:29:28
问题 I do not know if the exact request in title is possible, but if not; i would really appreciate an alternate solution. I have this pre save method of mongoose ownerSchema.pre("save", function(next) { const owner = this; bcrypt.genSalt(10, function(err, salt) { bcrypt.hash(owner.password, salt, function(err, hash) { // Store hash in your password DB. owner.password = hash; next(); }); }); }); When i save new user(owner) a hash is created successfully and all is good> The problem occurs when i

I want my pre('save') mongoose function to operate only once

落花浮王杯 提交于 2021-02-05 10:28:17
问题 I do not know if the exact request in title is possible, but if not; i would really appreciate an alternate solution. I have this pre save method of mongoose ownerSchema.pre("save", function(next) { const owner = this; bcrypt.genSalt(10, function(err, salt) { bcrypt.hash(owner.password, salt, function(err, hash) { // Store hash in your password DB. owner.password = hash; next(); }); }); }); When i save new user(owner) a hash is created successfully and all is good> The problem occurs when i

react js class poll convert into react hooks poll

限于喜欢 提交于 2021-02-05 09:47:23
问题 this my code for react component "class" base poll but I want to convert this form into react hooks so need help...!I don't understand How can I do this...!please help please help please help please help please help please help please help please help please help please help please help please help please help please help please help please help please help please help import React, { Component } from "react"; import Poll from "react-polls"; // Declaring poll question and answers const

react js class poll convert into react hooks poll

梦想的初衷 提交于 2021-02-05 09:47:14
问题 this my code for react component "class" base poll but I want to convert this form into react hooks so need help...!I don't understand How can I do this...!please help please help please help please help please help please help please help please help please help please help please help please help please help please help please help please help please help please help import React, { Component } from "react"; import Poll from "react-polls"; // Declaring poll question and answers const

MERN: Added a User object to another Model's array, prevented duplicate additions, but now it prevents OTHER users too

自古美人都是妖i 提交于 2021-01-29 13:06:52
问题 My app has two Models. User and Tournament. User model has username and _id (mongodb). Tournament model has participants which is an Array. I'm trying to make it so each and every user who signs up to a tournament can do so only once. I wrote an Express route to POST to a tournament's participants array: router.post('/:id', (req, res) => { Tournament.findById(req.params.id) .then(tournament => { const userSignedUp = (participantsArray, user) => { return participantsArray.some(arr => arr.user

Why does MongoDB not update unless I call “.then res.json(…)” after findOneAndUpdate?

守給你的承諾、 提交于 2021-01-29 07:03:21
问题 understanding questions here. I am doing a MERN setup website, and I was updating a field in my database like this: router.post("/updateLogApprovementStatus", (req, res) => { User.findOneAndUpdate( { _id: req.body.userId }, { $set: { log: req.body.newData } } ).then(user => res.json(user.log)); }); But after doing repeated calls to the api with correct data, my data field wasn't updating. However, when I do this: router.post("/updateLogApprovementStatus", (req, res) => { User.findOneAndUpdate