#MONGODB CLUSTER
35 messages · Page 1 of 1 (latest)
Huh? That’s just how arrays work…
Yes, but how do I stop before they are numbers without the name of the skins?
Huh? What do you want to stop there?
I was wondering how to just add the skins name to the array or something else as long as it's just the name
You literally do… but arrays always do contain stuff indexed by numbers. The numbers you see there aren’t values inside the array, they only are the indexes of the values
Okay, I tried to check inside the array if this value already exists, in this case this value already exists, but when I check using User?.Perfil?.skins === currentPageData.name, it says it's not in the array, probably I'm not doing it the right way.
And what returns from currentPageData.name, is in the database
Because an array won’t ever be equal to an element of that array.
Array.prototype.includes()
The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.
Like this?
It works, but imagine that I just added the value and then I check and it returns the empty array and if I restart the bot it appears in the array
I'm using $push has something to do with it, why not save it right away?
It does save right away (in db), but you probably don’t update the variable you got from DB earlier
It's like this right now, how do I fix it?
Depends, how and where did you declare User and how and where do you try to access it without it having the newly updated skins?
I defined at the beginning of the code
I won‘t be able to help you if you keep on sending screenshots of single lines of your code without context…
SOrry
Then you‘d need to reassign User after you updated in DB to the updated value
Not sure if findOneAndUpdate returns the updated document, if it does just do User = UserModel.findOneAndUpdate(…)
If not you need to findOne after that update call
I did it like this and it worked
Thank you
In mongoose you can return updated DBs as new: true
const DB = await nameOfSheama.findOneAndUpdate(
{ id: idToFind },
{update: update},
{new: true}
)
console.log(DB.update) // updated value
If one not. Made do
Mongodb.create({ stuff to make here )}
MONGODB CLUSTER