0

I have some inputs. User fills them and clicks send button. I want the data to store in database (couchDB).

The problem: I can save in database one object(div with multiple inputs). database

But when the user creates another div with inputs and tries to send 2 of them or even more - I get an error node cmd

what I have so far:

this is the structure I am trying to send:

structure

and this is a code:

App:

 handleSubmit = (event) => {
    event.preventDefault();
    let myRequest = new Request(
        'http://localhost:80/send',
        {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(
                this.state.divs // <- here is an array of objects. Won't work. 
                                // But if I send only the first one  `this.state.divs[0]`  it will do 
                                // the job and data will be stored in database as on the first picture.
            )
        }
    );
     fetch(myRequest)
        .then(res => res.json())
        .catch(err => console.log(err))
   };

Server:

server.post('/send', (req, res) => {
questionsDB.insert(
    req.body
).then(
    (antwort) => {
        console.log(antwort);
        res.send(JSON.stringify({
            status: 'ok'
        }))
    }
  );
});

What I am doing wrong? Would appreciate any help.

1 Answer 1

1

My thought is you cannot insert an array of objects using the insert function. You have to loop through each object or use a method for bulk inserts.

Sign up to request clarification or add additional context in comments.

1 Comment

Right! bulk() method! Oh my.... Thank you! You saved me )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.