1
Let data = {
              _id : "7302774",
              count : 25,
              Itmems : [{
                           image: "abc",
                           url: "28rudjj.com"
                        },
                        {
                           image: "abcd",
                           url: "aaa.com"
                        }
                       ]
            }

My mongodb data

I hope, change url Example const oldUrl = "aaa.com" const newUrl = "bbb.com"

Let data = {
              _id : "7302774",
              count : 25,
              Itmems : [{
                           image: "abc",
                           url: "28rudjj.com"
                        },
                        {
                           image: "abcd",
                           url: "bbb.com"
                        }
                       ]
            }

hope result

await strapi.query('item').model.updateMany([
        { items: { $elemMatch: { url: oldUrl } } },
        {
            $project: {
                items: {
                    $filter: {
                        input: '$items',
                        as: 'item',
                        cond: {
                            $eq: ['$$item.url', oldUrl]
                        }
                    }
                }
            }
        },
        { $set: { items: { url: newUrl } } }
    ])

I try this code and updateMany => aggregate also error help me mongodb god user!!

If you have any information you want, I'll give you more.

  • Does this answer your question? [Mongoose not updating multiple matches](https://stackoverflow.com/questions/66657369/mongoose-not-updating-multiple-matches) – AlexisG Feb 18 '22 at 13:52

0 Answers0