Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何通过Node.js和Angular.js更新MongoDB中的文档_Javascript_Angularjs_Node.js_Mongodb - Fatal编程技术网

Javascript 如何通过Node.js和Angular.js更新MongoDB中的文档

Javascript 如何通过Node.js和Angular.js更新MongoDB中的文档,javascript,angularjs,node.js,mongodb,Javascript,Angularjs,Node.js,Mongodb,我在MongoDb中的文档如下所示: { "_id" : ObjectId("5550e710dad47584cbfe9da1"), "name" : "Serverraum1", "tables" : [ { "name" : "Table1", "nummer" : "1", "reihe" : "2",

我在MongoDb中的文档如下所示:

{
    "_id" : ObjectId("5550e710dad47584cbfe9da1"),
    "name" : "Serverraum1",
    "tables" : [
                  {
                    "name" : "Table1",
                    "nummer" : "1",
                    "reihe" : "2",
                   }
               ]
}
张贴方法:

app.post('/serverraeume', function (req, res) {
    console.log(req.body);
    db.serverraeume.update(req.body, function (req, res) {
    });
});
以及angular controller中的http post:

$scope.addSchrank = function (serverraum){  
    $http.post('/serverraeume', $scope.table);
}

我想在Document Serverraum1表中进行更新。如何在表中推送$scope.table?

要在文档
服务器RAUM1
表中通过推送
$scope.table
进行更新,mongodb函数您的POST方法应使用向数组添加值的运算符,除非该值已经存在,在这种情况下,对该数组不做任何操作:

app.post('/serverraeume', function (req, res) {
    console.log(req.body);
    var query = {"name" : "Serverraum1"}, // the query object to find records that need to be updated
        update = { "$addToSet": { "tables": req.body } }, // the replacement object
        options = {}; // defines the behaviour of the function
    db.serverraeume.update(query, update, options, function (req, res) {
        console.log(res);
    });
});

登录到
console.log(req.body)
的对象是什么?例如:{name:'Test',number:'2',row:'2'}