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.