this is the schema that I have now but I need to add more array as number 2, 3, 4 example: //post api Answer Just try to create a schema with an empty object like: Schema so you can add multiple elements. But your data completely depends on what you are sending in your API request.
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
Is there a way to optimize the upload of huge json files to mongodb
I am working on a project where I need to use a database in order to better manage my data, and so I decided to use MongoDB for performance reasons. After setting everything up, I made a script that uses a pipeline to download a zip file, unpack it, grab the XLS file inside and convert the content to JSON
the id of cart shows null in controller but i m sure i m sending it NODE JS
I m sending the id of the product from this view (I m using express and mongoose db) I m sure it is not null here then I have this middleware to receive it and here is the function post Cart When I first receive it in the postcard function I made a log and it gives me the log
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
Don’t store keys with empty string values in mongodb document
i would like to store a post as a document in mongodb. I’m using mongoose for modelling and the content is created by a user using a form. The content of the form is append to FormData and sending to server. This works so far. The only issue is, that empty fields, that are appended as empty strings in the
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
Speed Up and Simplify MongoDB Aggregate Function
I have the following function, which is quite complicated, but i’m hoping someone might be able to understand it help me simplify/speed it up. In this function i end up with an array that contains a list of primaryStores and the number of products coming from each one to my group of stores. However, it only counts the products, if
JavaScript, how to run a piece of code only once?
I am saving my .env content dynamically from the AWS secrets manager, but I want to save all values just once the server starts. What should be the approach? I am using TypeScript: Answer You could use a boolean to remember whether the code has been executed or not. Something like this: