Below Array this Exisiting in DataBase and
[{
    name: 'Courier Received by Investor',
    value: true
  },
  {
    name: 'Courier Sent By Investor',
    value: false
  },
  {
    name: 'Signed CA-Doc received',
    value: false
  },
  {
    name: 'Cheque/Payment Received',
    value: false
  },
  {
    name: 'Cancelled Cheque Received',
    value: false
  },
  {
    name: 'ID Proof Received',
    value: false
  },
  {
    name: 'Address Proof Received',
    value: false
  },
  {
    name: 'Signed CA pictures/scan received',
    value: false
  }
]


 I WANT TO UPDATE THESE BELOW FIELDS IN THE ABOVE ARRAY, CAN ANYONE HELP ME WITH THIS?


[{
    name: 'Courier Received by Investor',
    value: true
  },
  {
    name: 'Courier Sent By Investor',
    value: true
  },
  {
    name: 'Cheque/Payment Received',
    value: true
  }
]
0
Samala Sumanth 20 फरवरी 2019, 22:50

1 उत्तर

सबसे बढ़िया उत्तर

आप arrayFiltersका उपयोग करके फ़िल्टर्ड पोजिशनल ऑपरेटर

उदाहरण के लिए, यह मानते हुए कि आपने अपना दस्तावेज़ बनाया है, उसकी संरचना निम्न है (arrayField वह फ़ील्ड नाम है जिसका उपयोग आपके सरणी मान रखने के लिए किया जाता है):

{
    arrayField: [{
            name: 'Courier Received by Investor',
            value: true
        },
        {
            name: 'Courier Sent By Investor',
            value: false
        },
        {
            name: 'Signed CA-Doc received',
            value: false
        },
        {
            name: 'Cheque/Payment Received',
            value: false
        },
        {
            name: 'Cancelled Cheque Received',
            value: false
        },
        {
            name: 'ID Proof Received',
            value: false
        },
        {
            name: 'Address Proof Received',
            value: false
        },
        {
            name: 'Signed CA pictures/scan received',
            value: false
        }
    ]
}

आप Courier Sent By Investor के लिए सभी प्रविष्टियों को अपडेट कर सकते हैं और इसे निम्नानुसार true पर सेट कर सकते हैं:

db.collection.update({}, {
    $set: {
        "arrayField.$[element].value": true
    }
}, {
    multi: true,
    arrayFilters: [{
        "element.name": "Courier Sent By Investor"
    }]
})


0
Alex B. 20 फरवरी 2019, 20:18