I have a document like this:
_id: ObjectId("559c1d2ad8291bc9368b4568")
tablename: "IWEO_IWBB"
out_user: "pb"
out_email: "email"
out_date: "15.05.2015"
and want to add array like this:
"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"
}
],
In my old PHP-Server I used the code below to insert it. The right command is "update". In node.js it seems to be another command.
foreach($jArray as $value){
//$uuid = uniqid('', true);
$tablename = $value['tablename'];
$ean = $value["ean"];
$runtime = $value["runtime"];
$art = $value["art"];
$marker = $value["marker"];
$stammkost = $value["stammkost"];
$new_data = array(
//array (
'ean' => $ean,
'runtime' => $runtime,
'art' => $art,
'marker' => $marker,
'stammkost' => $stammkost,
'accepted' => '0'
//)
);
try {
$collection->update(array("tablename"=>$tablename),array('$push' => array("inventar" => $new_data)));
echo json_encode($collection);
}
catch ( MongoConnectionException $e ) {
echo '<p>Update failed</p>';
exit();
}
}
In my new node.js I use the code below:
tables.forEach(function(table) {
var tablename = table.tablename;
var name = table.name ;
var ean = table.ean;
var runtime= table.runtime;
var art = table.art;
var marker = table.marker;
var stammkost = table.stammkost;
console.log(tablename+" "+ean+" "+name+" "+runtime+" "+art+" "+marker+" "+stammkost);
OutAccept.update(function (err, data) {
if (err) console.log(err);
else {
console.log(data);
}
});
response.end();
//}
});
});
The output in console is:
IWEO_IWBB_01062015 1 name1 11337 A null null
{ ok: 0, n: 0, nModified: 0 }
IWEO_IWBB_01062015 2 name2 A null null
{ ok: 0, n: 0, nModified: 0 }
Why it isnt updated/inserted? Its the wrong command?