Ok so basically, whenever there is no data I make data by doing:
I want it so that if the data does exist it makes a new character in the array characters in a JSON format. I want it so that it does this but it finds the data by user ID. So something like:
!newcharacter characterimage charactername
and it pushes all this into a new json object in the array characters
Hi there @HK420
Right, I have tried to gather what I can from your post, so let me get this straight. You make a character if there is no data. Data in what? The characters array? So, you find data using:
Data.findOne({_id: theid}, (err, datafound)=>{
})
assuming you are using mongoose.
Then what do you want to do with that data? What do you want to do if data is found? Push to an array. What array? Is it in that Data that is found? Do you have schemas for where you want the data to go?
No, I don’t make a character if there is no data. I make the whole model when there’s no data for the user. For this specific command I want to make character data so that’s what I did. What I want to do is that whenever the command is executed, it makes a new JSON object in the array of characters.
An example would be:
[{
name: something,
images: [`something else`],
upvotes: 0,
downvotes: 0,
status: "Private",
CharacterID: character ID
}],
This data would be made in characters if there is no data that the user has.
I want it so if the user already has data, it makes another JSON object like:
Everything worked perfectly! Im just getting this in the console for some reason:
(node:14792) DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `useFindAndModify` option set to false are deprecated. See: https://mongoosejs.com/docs/deprecations.html#findandmodify
I think it’s just how my mongodb configuration is done.
Welcome back HK420! In MongoDB, I believe you have to pass settings like {useFindAndModify: true} in the connection argument. However, you’re using Mongoose, which might be different…