Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It doesnt appear the secrets! #3

Open
ezeloop opened this issue Apr 10, 2020 · 10 comments
Open

It doesnt appear the secrets! #3

ezeloop opened this issue Apr 10, 2020 · 10 comments

Comments

@ezeloop
Copy link

ezeloop commented Apr 10, 2020

I have all the code like the posted one, and it doesnt appear the secrets!

app.get("/secrets", function(req, res){
User.find({"secret": {$ne: null}}, function(err, foundUsers){
if (err){
console.log(err);
} else {
if (foundUsers) {
res.render("secrets", {usersWithSecrets: foundUsers});
}
}
});
});

in the db i have the secret, but i cant show them!

@hadihammad
Copy link

you need to edit secrets.ejs

@0514sm
Copy link

0514sm commented May 7, 2020

edit secrets.ejs with
<% usersWithSecrets.forEach(function(ele){ %>

<%= ele.secret%>

<%} %>

@jkalandarov
Copy link

Same problem with me.
First of all, it is not saving input (secret) into DB, that's why it is not rendering secrets.
I copied the code from here, but no change. Tried restarting DB and so on. Any idea why?

@kostiastrong
Copy link

I copied the code from here, but no change. Tried restarting DB and so on. Any idea why?

I guess you forgot to add submit post route:

app.post("/submit", function(req, res) {
  const submittedSecret = req.body.secret;

  User.findById(req.user.id, function(err, foundUser) {
    if (err) {
      console.log(err);
    } else {
      if (foundUser) {
        foundUser.secret = submittedSecret;
        foundUser.save(function() {
          res.redirect("/secrets");
        });
      }
    }
  });
});

@harshptl176
Copy link

Have you update your user schema i.e add secrets: String in user schema?

@Webbuster99
Copy link

I am updated the userschema & also added the submit post route code but it's still not working.. how can I fix this secret route problem that can loop through all my secrets ??? plz help me

@mohitverma-2010
Copy link

req.user._id

Use this in submit post request, it will work!

@faizalkhan99
Copy link

req.user._id

Use this in submit post request, it will work!

Hey! I tried all of the things but none worked for me:( my code is exactly the same as Angela.

@shahkashif96
Copy link

shahkashif96 commented Sep 10, 2022

Hey!!
did u manage to solve the issue? I am facing exactly the same issue. But i have an extra issue.. my secret isnt even getting saved in the db.

@SKSALI1
Copy link

SKSALI1 commented Sep 19, 2023

it is deprecated, and dont know how to write them now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests