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?