Javascript 通过mongoose动态更新数组列表中的元素
假设mongoose数据库中的对象是…(集合的名称是user) 现在,我想动态地将标题数组的索引号1更改为某个值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]},
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);}