Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
How to update array of input values mapped from mongodb at once not by id?

There is a list of let's say animals. I have them all set in MongoDB and receive them through redux actions with await axios.get("/api/getanimals") then i map them with (I removed all classes from code snippet just to shorten the code)

{animalsList.map((item, i) => {
            return (
              <div key={i}>
                <div>
                  <input
                    value={item.name}
                    onChange={(e) => handleAnimals(e, i)}
                  ></input>
                  <input
                    value={item.category}
                    onChange={(e) => handleAnimals(e, i)}
                  />
                </div>
                <div>
                  {animalsList.length !== 1 && (
                    <button
                      onClick={() => handleRemoveAnimals(i)}
                    >
                      Remove
                    </button>
                  )}
                  {animalsList.length - 1 === i && (
                    <button
                      onClick={handleAddAnimals}
                    >
                      Add
                    </button>
                  )}
                </div>
              </div>
            )
          })}
   

It's mapping them perfectly like i wanted Input form and creating array (i can see it with JSON.stringify Array below the form), but now we get to the hard part. How do i create form handler and api post request to update all edited inputs at once as separate objects in database like i receive them with await Animals.find({})? I also need to be able to add or remove new animals that's what those dynamic buttons with onClick are for.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!