Reputation: 23
here is my schema
const CustomerSchema = mongoose.Schema(
{
name: {
type: String,
trim: true,
},
purchased: {
modelsId: [{
type: mongoose.Schema.ObjectId ,
trim: true,
}],
collectionsId: [{
type: mongoose.Schema.ObjectId,
trim: true,
}]
}
},
{ timestamps: true }
);
and i want to add an array to modelsId array in purchased object with mongoose
Customer.findOneAndUpdate({ _id: customer._id }, { $addToSet: { 'purcased.modelsId': { $each: modelsId } } },
{ new: true }).then(res => {
console.log('response', res)
}).catch(e => {
console.log('error', e)
})
and it's not working! thank you for your help!
Upvotes: 0
Views: 43
Reputation: 120
Looks like you may just have a simple spelling error? Try changing 'purcased.modelsId'
to 'purchased.modelsId'
. You're just missing an 'h' I think!
Upvotes: 1