0

How to save new / update existing mongoose nested array? Do we need different function to achieve (save new/update existing) this or do we need separate function for each task?

Dummy Model 
var user = new Schema({
    name : String,
    cars: [{brand: String, prices:[ {color : String, value: String}] }],

}

let saveUpdate = await User.findOneAndUpdate(
     { _id: req.id }, 
     { $set: { cars: ----   } }
 );

I have to save new car details and update car model or update price value based on color field

2
  • I've answered similar question recently. Maybe you would like to take a look at it, on how to create a efficient document - stackoverflow.com/a/71013819/2822041 Commented Feb 8, 2022 at 6:56
  • I have multiple nested , let me try with your example Commented Feb 8, 2022 at 6:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.