Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Updating a nested object in a document using mongoose

let userData = {productCode: "4pf"}
let dataToBeUpdated = {claims: ["abc", "def"]}
ProductModel.findOneAndUpdate({"products.productCode": userData.productCode}, {$set: {"products.$": dataToBeUpdated}})
Source by www.mongodb.com #
 
PREVIOUS NEXT
Tagged: #Updating #nested #object #document #mongoose
ADD COMMENT
Topic
Name
8+5 =