Mongodb updateMany not working in nodejs

0 votes

I have a collection called imported_products with documents as following,

{
    "_id" : ObjectId("61dd75ab9c56561c4e36ae64"),
    "shop" : "lotesting.myshopify.com",
    "shopUserData" : {
        "name" : "LoTesting",
        "email" : "test@gamil.com"
    },
    "productData" : {
        "title" : "Fiodio Rainbow Membrane Gaming Keyboard, Quiet Wired Computer Keyboard, 104 Silent Keys, 26 Anti-Ghosting Keys, Spill Resistant, Multimedia Control for PC and Desktop",
        "description" : "Easy Operation & Broad Compatibility: As a plug-and-play device, this USB wired gaming keyboard does not need any software support, serving as a great choice for PC, laptop, computer keyboard. It is compatible with Win XP / Win7 / Win8 / Win10.",
        "price" : 30.74,
        "priceWithCurrency" : "$30.74",
        "images" : [
            "https://m.media-amazon.com/images/I/51YO1+k0bIL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/510vNeFx5QL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51XA0CmhmEL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/41Ywwi-KgiL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51lq5qZLJdL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51Nwf+EAaDL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/41tljLXU40L._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51nVhirK6ML._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51xMxfShNGL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/519oWM+mnzL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51YO1+k0bIL._SL500_.jpg"
        ],
        "ASIN" : "B086168Y25",
        "marketPlace" : "www.amazon.com",
        "settings" : {
            sendNotification: true
        },
        "shopifyProductId" : 6755890495624,
        "productUrl" : "https://www.amazon.com/FIODIO-Comfortable-Anti-Ghosting-Resistant-Multimedia/dp/B086168Y25/ref=sr_1_1_sspa?keywords=gaming+keyboard&pd_rd_r=9a66bdd8-f451-45a7-931f-999bb794436d&pd_rd_w=EDbsr&pd_rd_wg=HKpTZ&pf_rd_p=12129333-2117-4490-9c17-6d31baf0582a&pf_rd_r=TTMA6EPTSPTT6ZVVMC2Q&qid=1641903304&sr=8-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEyNEtSUTlGSDZOSEwzJmVuY3J5cHRlZElkPUEwNDE3NDI3MkROTkM4QTFOUE44VyZlbmNyeXB0ZWRBZElkPUEwMzQyOTQ4MVNYODZWTFgzN1RMUSZ3aWRnZXROYW1lPXNwX2F0ZiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU="
    },
    "created_at" : ISODate("2022-01-11T12:18:51.260Z")
}
{
    "_id" : ObjectId("61dd75bf9c56561c4e36ae65"),
    "shop" : "lotesting.myshopify.com",
    "shopUserData" : {
        "name" : "LoTesting",
        "email" : "test@gmail.com"
    },
    "productData" : {
        "title" : "Fiodio Rainbow Membrane Gaming Keyboard, Quiet Wired Computer Keyboard, 104 Silent Keys, 26 Anti-Ghosting Keys, Spill Resistant, Multimedia Control for PC and Desktop",
        "description" : "Easy Operation & Broad Compatibility: As a plug-and-play device, this USB wired gaming keyboard does not need any software support, serving as a great choice for PC, laptop, computer keyboard. It is compatible with Win XP / Win7 / Win8 / Win10.",
        "price" : 30.74,
        "priceWithCurrency" : "$30.74",
        "images" : [
            "https://m.media-amazon.com/images/I/51YO1+k0bIL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/510vNeFx5QL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51XA0CmhmEL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/41Ywwi-KgiL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51lq5qZLJdL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51Nwf+EAaDL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/41tljLXU40L._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51nVhirK6ML._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51xMxfShNGL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/519oWM+mnzL._SL500_.jpg",
            "https://m.media-amazon.com/images/I/51YO1+k0bIL._SL500_.jpg"
        ],
        "ASIN" : "B086168Y25",
        "marketPlace" : "www.amazon.com",
        "settings" : {
            sendNotification: true
        },
        "shopifyProductId" : 6755890692232,
        "productUrl" : "https://www.amazon.com/FIODIO-Comfortable-Anti-Ghosting-Resistant-Multimedia/dp/B086168Y25/ref=sr_1_1_sspa?keywords=gaming+keyboard&pd_rd_r=9a66bdd8-f451-45a7-931f-999bb794436d&pd_rd_w=EDbsr&pd_rd_wg=HKpTZ&pf_rd_p=12129333-2117-4490-9c17-6d31baf0582a&pf_rd_r=TTMA6EPTSPTT6ZVVMC2Q&qid=1641903304&sr=8-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEyNEtSUTlGSDZOSEwzJmVuY3J5cHRlZElkPUEwNDE3NDI3MkROTkM4QTFOUE44VyZlbmNyeXB0ZWRBZElkPUEwMzQyOTQ4MVNYODZWTFgzN1RMUSZ3aWRnZXROYW1lPXNwX2F0ZiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU="
    },
    "created_at" : ISODate("2022-01-11T12:19:11.391Z")
}

I am trying to update all of documents for a certain category under a collection in my mongodb. But, i cannot update. When i try the same query in mongodb shell, it works.

What i want to do is that, for a specific shop i want to update the settings object that is a nested object of producdData object in every document and for all documents that include that shop, in this case, "lotesting.myshopify.com". I want to update or create that settings object with certain key, value pairs.

I tried the follwoing.

export const updateProductsSettings = async (db, shop, settingsObj) => {
  try {
    await db.collection('imported_procucts').updateMany(
      { shop },
      {
        $set: {
          'productData.settings.automaticPriceChange':
            settingsObj.automaticPriceChange,
          'productData.settings.priceChangePercentage':
            settingsObj.priceChangePercentage,
        },
      }
    );
  } catch (err) {
    throw new Api500Error(err);
  }
};

The identical query executes well in mongodb shell but not node. It cannot even compare to the shop, js. I verified that the shop I am passing is correct, yet it has no matches. In addition to not updating anything, it also doesn't produce any errors. 

Jun 27 in Node-js by Vaani
• 7,020 points
37 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Node-js

0 votes
0 answers

npm command not working after installing nodejs in windows10?

i have installed nodejs from nodejs website. ...READ MORE

Aug 11 in Node-js by Neha
• 8,740 points
6 views
0 votes
1 answer

How to check if a collection exists in Mongodb native nodejs driver?

Hello @kartik, The collectionNames method of the native driver's Db object accepts ...READ MORE

answered Nov 27, 2020 in Node-js by Niroj
• 82,740 points
9,844 views
0 votes
1 answer

Nodejs: question of type input with npm inquirer not working

The right code should be: const outPath = ...READ MORE

answered Jun 7 in Node-js by Neha
• 8,740 points
131 views
0 votes
1 answer

NodeJS express get request is not working on mobile

For your API call, try to add ...READ MORE

answered Jun 7 in Node-js by Neha
• 8,740 points
88 views
0 votes
1 answer

NodeJS express get request is not working on mobile

For your API call, try to add ...READ MORE

answered Jun 9 in Node-js by Neha
• 8,740 points
11 views
0 votes
1 answer

Nodejs Instagram videos downloader not working

Firstly, Initialize a package.json file with default values. npm ...READ MORE

answered Jun 9 in Node-js by Neha
• 8,740 points
83 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,008 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP