Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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
Arrays 更新MongoDB中嵌入文档下的第n个数组值_Arrays_Mongodb_Embedded Documents - Fatal编程技术网

Arrays 更新MongoDB中嵌入文档下的第n个数组值

Arrays 更新MongoDB中嵌入文档下的第n个数组值,arrays,mongodb,embedded-documents,Arrays,Mongodb,Embedded Documents,我只想更新该数组中的第n个位置,而不是更新数组中的所有值。 db.patient.insertMany([ {名字:“桑加”,姓氏:“杜赖”,年龄:27岁,病史:{疾病:[“寒冷”,“乌莱尔基”]}}) 在这里,你能告诉我如何更新价值“冷”到“热”,仍然是一样的 我已经知道另一种存档方法,但使用它我必须更新数组中的所有值: db.patient.updateOne({firstName:“Thanga”,“history.disease:“Cold”}, {$set:{姓氏:“尤维”,“年龄”:

我只想更新该数组中的第n个位置,而不是更新数组中的所有值。
db.patient.insertMany([
{名字:“桑加”,姓氏:“杜赖”,年龄:27岁,病史:{疾病:[“寒冷”,“乌莱尔基”]}})

在这里,你能告诉我如何更新价值“冷”到“热”,仍然是一样的

我已经知道另一种存档方法,但使用它我必须更新数组中的所有值:
db.patient.updateOne({firstName:“Thanga”,“history.disease:“Cold”},
{$set:{姓氏:“尤维”,“年龄”:28岁,“病史.疾病”:[“发烧”,“溃疡”]}
)

有人能告诉我如何将“只感冒”更新为“发烧”吗?

试试这个


你能试试db.patient.updateOne({firstName:“Thanga”,“history.disease:“Cold”},{$set:{lastName:“Yuvi”,“age:”28,“history.disease.$”:“Fever”}})
?@mickl非常感谢你!!这是完美的工作,我会把它作为一个答案,也许它会帮助别人
db.patient.update(
  {
    "firstName":"Thanga",
    "history.disease":"Cold"
  }, 
  {
    $set:{
      "lastName":"Yuvi",
      "age":28,
      "history.disease.0":"Fever"
   }
  })