Answer the question
In order to leave comments, you need to log in
How to add data to existing mongodb collection document?
There is a React application that sends requests to the Node, express (mongoose) server, which in turn writes data to mongodb.
On the main page there is a Select from which information is obtained and when the button is pressed, the data is sent to the server, saved in the database and the transition to the second page takes place.
On the second page, there are also two Selects from which information is collected and should also be saved to the collection, in the document that was created from the first Select, but a new document with data is created.
How can I assign one document per user so that each user has their own document in the mongodb collection.
Advise where it is possible to find the information about it and to esteem.
Answer the question
In order to leave comments, you need to log in
In general, I found a solution, maybe it's not quite right)))
Maybe someone will tell you it's worth doing this.
In React, when visiting a site, the user is given a number (which is generated from Date.now()) which is stored in sessionStorage. When data is sent to the server for the first time, this id is also sent to the server and to the database.
On the server, its value is exported to the second page, where the data from the second Select comes.
In the database, we look for a document in mongodb by id (which was in sessionStorage and imported to the second page) and write data to it. As a result, it turns out to write all the data into the document that was created when the data was first sent to the database.
should also be saved to the collection, in the document that was created from the first Select, but a new document with data is created.
How can I assign one document per user so that each user has their own document in the mongodb collection.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question