My JSON object as shown below and I want to update one product details of user 1 by using User id and product id
{
"_id": {
"$oid": "5b544ee53379672e184c9aa2"
},
"user_firstname": "user 1",
"user_lastname": "test123",
"products": [
{
"_id": {
"$oid": "5b5615741026382bf0b784a6"
},
"product_name": "product 1",
"product_price": {
"$numberInt": "25"
},
},
{
"_id": {
"$oid": "5b5615ba1026382bf0b784a7"
},
"product_name": "product 2",
"product_price": {
"$numberInt": "25"
},
},
]
}{
"_id": {
"$oid": "5b574e38b714e420683ae839"
},
"user_firstname": "user2",
"user_lastname": "user last name",
"products": [
{
"_id": {
"$oid": "5b574e7fb714e420683ae83b"
},
"product_name": "product1",
"product_price": {
"$numberInt": "10"
},
},
],
}
Here two users are there and they have some products. Now I want to update one product details of particular user by finding his ID. In the above example I want to update "$oid": "5b5615ba1026382bf0b784a7" product details of the user with id "$oid": "5b544ee53379672e184c9aa2"
This details I will get from the user
updateproducts = {
product_id : "5b5615ba1026382bf0b784a7"
product_name : "updated product"
product_price :"250"
userID : "5b544ee53379672e184c9aa2"
}
And this is my function
module.exports.updateProducts = function(updateproducts, callback) {
var id = updateproducts.product_id;
sellers.update({ "_id": ObjectId(id) }, { '$set': updateproducts },
callback);
}
but it caused the following error:. How to I fix it?". See the final question mark. All you have there is "I want to do this". Note the absence of question mark. This is not a coding service. You don't just post your requirements and have people write the code for free.
– JB Nizet Jul 28 '18 at 06:10