Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.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 在angular meteor中使用$push操作符更新mongodb_Javascript_Angularjs_Mongodb_Meteor_Mongodb Query - Fatal编程技术网

Javascript 在angular meteor中使用$push操作符更新mongodb

Javascript 在angular meteor中使用$push操作符更新mongodb,javascript,angularjs,mongodb,meteor,mongodb-query,Javascript,Angularjs,Mongodb,Meteor,Mongodb Query,我正在尝试将阵列从一个集合推送到另一个集合。 这是我在服务器js中使用的代码 updateSettings: function(generalValue) { let userId = Meteor.userId(); let settingsDetails = GeneralSettings.findOne({ "_id": generalValue }); Meteor.users.update({ _id: user

我正在尝试将阵列从一个集合推送到另一个集合。 这是我在服务器js中使用的代码

    updateSettings: function(generalValue) {
     let userId = Meteor.userId();
       let settingsDetails = GeneralSettings.findOne({
   "_id": generalValue
 });
            Meteor.users.update({
     _id: userId
   }, {
     $push: {

       "settings._id": generalValue,
       "settings.name": settingsDetails.name,
       "settings.description": settingsDetails.description,
       "settings.tag": settingsDetails.tag,
        "settings.type": settingsDetails.type,
       "settings.status": settingsDetails.status
     }


   })

}
更新设置是meteor方法。GeneralSettings是第一个集合,user是第二个集合。我想将数组从GeneralSettings推送到users集合。当我尝试这个的时候,我得到的结果是

 "settings" : {
    "_id" : [ 
        "GdfaHPoT5FXW78aw5", 
        "GdfaHPoT5FXW78awi"

    ],
    "name" : [ 
        "URL", 
        "TEXT" 

    ],
    "description" : [ 
        "https://docs.mongodb.org/manual/reference/method/db.collection.update/", 
        "this is a random text" 

    ],
    "tag" : [ 
        "This is a demo of an Url selected", 
        "demo for random text"
    ],
    "type" : [ 
        "url", 
        "text"
    ],
    "status" : [ 
        false, 
        false
    ]
}
但我想要的结果是

 "settings" : {
    "_id" : "GdfaHPoT5FXW78aw5",

    "name" :  "URL", 

    "description" :  
        "https://docs.mongodb.org/manual/reference/method/db.collection.update/", 

    "tag" :"This is a demo of an Url selected", 

    "type" :  "url",


    "status" :    false 



},

为了获得此输出,需要在my server.js中进行哪些更改

这是一种您“不想”使用“点符号”的情况。操作员期望并
对象
或基本上要将“右侧”添加到“左侧键”中命名的数组中:


当您在每个项目上使用“点符号”时,这就是要求为提供的“每个”单独“键”创建“数组”。因此,它只是一个“一”数组键,以及作为参数添加的对象。

这是一个您“不想”使用“点表示法”的情况。操作员期望并
对象
或基本上要将“右侧”添加到“左侧键”中命名的数组中:


当您在每个项目上使用“点符号”时,这就是要求为提供的“每个”单独“键”创建“数组”。因此,它只是一个数组键,要添加的对象作为参数。

尝试使用
$set
而不是
$push
。您推送到数组,但我不认为
设置。例如,id
是一个使用
$set
而不是
$push
的数组。你推到数组,但我不认为
设置。例如,id
就是数组
// Make your life easy and just update this object
settingDetails._id = generalValue;

// Then you are just "pushing" the whole thing into the "settings" array
Meteor.users.update(
  { _id: userId }, 
  { "$push": { "settings": settingDetails } }
)