Skip to content
Advertisement

Tag: mongodb

Cast to string failed for value Error when submitting the form, using FileBase from React to convert the image

I have an error when i try to post this schema data into Form.js. Mongoose schema looks like this: Logic for creating post is like this: I’m uploading image as String and I’m converting image using base64 from React like this- When I try to submit form, I get error like – {“message”:”PostMessage validation failed: selectedFile: Cast to string failed

Looping Over And Array of Objects and Updating Each One

I’m trying to update objects inside an array based on specific conditions that I check using two functions. I couldn’t achieve this with the match feature available in mongoose. As you can see below, I’m trying to loop over the array of posts, send each post and check if it fulfills a condition, then update it using findOneAndUpdate. The functions

MongoDB FIND method does not work in code

so when I try to find items in a collection through the console using the method db.DB_NAME.find({ x: y }, it works just fine. However, when trying to do the same in the code, it does not work. Perhaps it is worthy mentioning that the method findOne works great within the code. Consulting through the console Code: What I get

MongoDB Problems while inserting nested data

I try to build a database for a giveaway bot using MongoDB. Once a new giveaway is created the bot runs the following code to write the new giveaway into the databank: Giveaways should be a nested document in the document with the server’s information. My schemas for this looks like this: In my Mongo Atlas I have 2 collections

Advertisement