Monday, 3 December 2018

Using mongoose find() method with a variable

Hello all,​I'm trying to understand why I can't use a variable with the mongoose find method. The code below returns a result set.async function getUser(email){let users = await Users.find({email: /bar$/i }).limit(10) // Limit the number of results.select({firstName: 1, lastName: 1}); // Select what elements to getconsole.log(users);return users}​however is I make the simple following change, using the email variable as part of the find method.async function getUser(email){email = "bob.barker@thepriceisright.com";let users = await Users.find({email: email }).limit(10) // Limit the number of results.select({firstName: 1, lastName: 1}); // Select what elements to getconsole.log(users);return users}​It does not work.​Thought?​Kind regards​​​

Submitted December 04, 2018 at 01:33AM by sma92878

No comments:

Post a Comment