#returning undefined

14 messages · Page 1 of 1 (latest)

rocky kelp

I'm trying to make it so whenever i do /packs (color) I see all the packs with the color I put in, but if I try to do it like I have right now the names and values will be set to undefined. I know that it probably has something to do with my array, but I don't know how to fix it. Anyone able to help with that?

coral bearBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
spice perch

If that’s mongoose you should probably use findAll. And the result is already an iterable. You shouldn’t add it to an array (of length 1) to then forEach it (which will run exactly once) while trying to access properties on the iterable itself (which don’t exist, because they only exist on the elements of the iterable)

rocky kelp

if I don't put it in an array it'll say that forEach isn't a function

and findAll isn't a thing I'm pretty sure

I looked through the documentation and it's findOne for one document and just find for multiple

spice perch

It should though Thonk console.log(existUsername) then

rocky kelp

it shows both of the packs

it created both fields now, but everything is undefined

when I'm using findOne it works fine, but as soon as I use find it just stops working

so I think it's having trouble distinguishing the 2 packs and wants to throw everything everywhere?

spice perch

Because you don’t get the properties from the parameter of the forEach callback but still try to get it from the array itself

Should be u.packName and u.packCreator