0

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!

1
  • modelsId = ["5faee4ed9c90235da7765f32","5faee69b9c90235da7765f33"] Commented Nov 18, 2020 at 16:53

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

Comments

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.