Update deeply nested array in mongodb

后端 未结 1 473
花落未央
花落未央 2021-01-06 17:57

I am trying to update field value in mongoose.

{
    \"_id\" : ObjectId(\"5b62c772efedb6bd3f0c983a\"),
    \"projectID\" : ObjectId(\"0000000050e62416d0d758         


        
相关标签:
1条回答
  • 2021-01-06 18:06

    You can try with arrayFilters in mongodb

    var mongoose = require('mongoose')
    
    
    Temp.update(
      { "_id" : mongoose.Types.ObjectId("5b62c772efedb6bd3f0c983a") },
      { "$set": {
        "inspection_data.$[e1].locationAspects.$[e2].comments.$[e3].images.$[e4].title": "TableFan"
      }},
      { "arrayFilters": [
        { "e1._id": mongoose.Types.ObjectId("5b62c772fa02622a18655e7b") },
        { "e2._id": mongoose.Types.ObjectId("5b62c772fa02622a18655e80") },
        { "e3._id": mongoose.Types.ObjectId("5b62c772fa02622a18655e81") },
        { "e4.id": "1" }
      ]}
    )
    

    Note: You have to cast _id to ObjectId

    0 讨论(0)
提交回复
热议问题