2

I have a mongoose Schmea, which looks like this: (Simplified)

const refreshSchema = new mongoose.Schema({
    token: String,
    expiration: Date
})

const userSchema = new mongoose.Schema({
    email: String,
    refreshTokens: [refreshSchema],
})

I have added some objects to the array refreshTokens, now I am trying to delete some of them

await User.update({email: this.email}, {$pull: { token }})
await User.updateOne({email: this.email}, {$pullAll: [{ token }]})

Neither works, the object still exists in refreshTokens. What am I doing wrong?

1
  • What is the value of token? Commented Nov 13, 2022 at 12:58

1 Answer 1

1

The form of $pull operator is:

{ $pull: { <field1>: <value|condition>, <field2>: <value|condition>, ... } }

So your query should be:

await User.update({email: this.email}, {$pull: { refreshTokens: { token } }})
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.