0

what to do:

The user sends a string via post. the string is parsed as JSON-string. This questions follows the impression of the answer of Insert Array in existing Document Blake Seven to make it better to understand.

thanks in advance

The parsed data is like:

var inventor =  [
    {
        "tablename": "AAAA",
        "ean": "2",
        "name": "name2",
        "runtime": "0",
        "art": "null",
        "marker": "null",
        "stammkost": "null",
        "accepted": "0"
    },
    {
        "tablename": "AAAA",
        "ean": "1",
        "name": "name1",
        "runtime": "0",
        "art": "null",
        "marker": "null",
        "stammkost": "null",
        "accepted": "0"
    }
        {
        "tablename": "BBBB",
        "ean": "3",
        "name": "name3",
        "runtime": "0",
        "art": "null",
        "marker": "null",
        "stammkost": "null",
        "accepted": "0"
    }
];

`

The existing documents are like

 tablename: "AAAA"
 OutUser: "ZZZ"
 OutEmail: "[email protected]"
 OutDate: "01.01.2015"
 _id: ObjectId("559c2f04f41dde0c1b39574c")
 __v: 0

means:

each inventor-array shoud be added to the right tablename.

so after all is done every existing document gets added the inventor-data, depending on the tablename in it.

 tablename: "AAAA"
 OutUser: "ZZZ"
 OutEmail: "[email protected]"
 OutDate: "01.01.2015"
 inventar: [
    {
        "ean": "2",
        "name": "name2",
        "runtime": "0",
        "art": "null",
        "marker": "null",
        "stammkost": "null",
        "accepted": "0"
    },
    {
        "ean": "1",
        "name": "name1",
        "runtime": "0",
        "art": "null",
        "marker": "null",
        "stammkost": "null",
        "accepted": "0"
    }
]
 _id: ObjectId("559c2f04f41dde0c1b39574c")
 __v: 0

This is my existing code and after that i got stuck....

app.post('/out_accepted', function(request,response){
    //request string as parameter
    var jsonString=request.body.json;
    //parse string in JSON-String
    var inventar = JSON.parse(jsonString);

Can you follow me?

4
  • This is exactly the same question as your mentioned question Insert Array in existing Document Commented Jul 9, 2015 at 4:34
  • yes it is, but wanted to make clearer the whole thing. the Inventor Post json here Different, because the tablename is inside. I dont know if it was clear in the other thread Commented Jul 9, 2015 at 4:43
  • It was clear enough, which is why you got an answer. You cannot post the same question here twice. If you think you need more information ( and this looks all the same, and actually less detail ) then you edit your original question, and possibly alert anyone who answered of the additional information. This is a "duplicate" question. They get removed. And probably downvoted heavily when people see what you have done. Commented Jul 9, 2015 at 5:00
  • I marked it as solved to close it and I will later edit the other question with a few more details. thanks Commented Jul 9, 2015 at 5:06

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.