Home > database >  How to update values in string array in all documents? - MongoDB
How to update values in string array in all documents? - MongoDB

Time:11-04

I have in my collection this structure:

{
    _id: ObjectId('...'),
    images: [
        "images/key1",
        "images/key2",
        "images/key3",
        "images/key4"
    ],
    .... ,
    ....
}

So, I want to update all documents to:

{
    _id: ObjectId('...'),
    images: [
        "key1",
        "key2",
        "key3",
        "key4"
    ],
    .... ,
    ....
}

Replacing in all values 'images/' with ''. Thanks

  • Related