Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.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/1/wordpress/13.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 通过mongoose动态更新数组列表中的元素_Javascript_Node.js_Arrays_Mongodb_Mongoose - Fatal编程技术网

Javascript 通过mongoose动态更新数组列表中的元素

Javascript 通过mongoose动态更新数组列表中的元素,javascript,node.js,arrays,mongodb,mongoose,Javascript,Node.js,Arrays,Mongodb,Mongoose,假设mongoose数据库中的对象是…(集合的名称是user) 现在,我想动态地将标题数组的索引号1更改为某个值 let new_title = "new title"; let index = 1; // updating the array through mongoose dynamically.. user.updateOne({email: "example@gmail.com , title : user.title[index]},

假设mongoose数据库中的对象是…(集合的名称是user)

现在,我想动态地将标题数组的索引号1更改为某个值

let new_title = "new title";
let index = 1;
// updating the array through mongoose dynamically..
user.updateOne({email: "example@gmail.com , title : user.title[index]},
               { $set: {"title.$" : new_title}}).(err , suc)=>{
               if (err) throw err;
               if (suc){ console.log(suc);}
但是我的数组没有得到更新。这种方法是行不通的。 根据文档-->“title.$”应该与查询中传递的title元素匹配

如果在mongodb中使用任何或任何其他方法动态更新数组

请尝试:{$set:{“title”:new_title},请告诉我错误
let new_title = "new title";
let index = 1;
// updating the array through mongoose dynamically..
user.updateOne({email: "example@gmail.com , title : user.title[index]},
               { $set: {"title.$" : new_title}}).(err , suc)=>{
               if (err) throw err;
               if (suc){ console.log(suc);}