Closed paulinal3 closed 2 years ago
Also still wondering about if findOrCreate()
is a built in mongoose method or if I should install the npm package!
To answer the second Q, I'm pretty sure findOneAndUpdate creates a new doc of it doesn't exist already. TBH I didn't realize mongoose didn't have a findOrCreate
can you explain "The conditional seems to work but it skips over the return in those conditionals except for alphabetically"?
can you explain "The conditional seems to work but it skips over the return in those conditionals except for alphabetically"?
I console logged under the conditionals but before the actual sort runs and got the correct console logs when it changed state but the actual sort functions to be returned aren't working.
The "new" and "updated" conditionals just return the reverse of the alphabetically sort and the "old" returns alphabetically.
So I'm assuming it's because I have it originally return the playlists alphabetically that's messing with everything.
To answer the second Q, I'm pretty sure findOneAndUpdate creates a new doc of it doesn't exist already. TBH I didn't realize mongoose didn't have a findOrCreate
Ah gotcha! So it's fine to use findOneAndUpdate for a post route?
Ah ok so it's like the callbacks you're passing into the .sort() aren't working as expected?
And yeah I think it's fine to use that OR the npm module. Up to you.
Ah ok so it's like the callbacks you're passing into the .sort() aren't working as expected?
Correct and I'm not sure why. because even with the array being sorted alphabetically first, I'm still looking for specific dates to sort by afterwards
still stuck on this if anyone has ideas!
What stack are you using?
(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)
MERN
What's the problem you're trying to solve?
Trying to sort my array in different ways (newest, oldest, most updated
Post any code you think might be relevant (one fenced block per file)
different code I've tried
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
No error, just not sorting the way I want to
What is your best guess as to the source of the problem?
The conditional seems to work but it skips over the return in those conditionals except for alphabetically
What things have you already tried to solve the problem?
Refactoring, google, peer to peer