2

I have a small, yet important issue with my code that uses Mongoose/MongoDB. I can't seem to be able to use $pull or $pullAll in Model.findOneAndUpdate({}).

My code is the following:

db?.updateOne({ $pull: {
                AutoRole: {
                    Roles: [value],
                }
            }
            });

And this is my Model schema:

const guildSchema = new mongoose.Schema({

    GuildID: String,
    AuditChannel: String,
    AutoRole: {
        Roles: Array
    },

});

So far I'm out of ideas on how to make it work. I was wondering if I was doing it wrong, but I can't seem to find what I'm doing exactly wrong.

6
  • I think it's $pull : { "AutoRole.Roles": ... } Commented Sep 15, 2022 at 14:27
  • Lemme give that one a try. Commented Sep 15, 2022 at 14:28
  • @CollinD Doesnt work, still. ``` db?.updateOne({ $pull: { "AutoRole.Roles": [value] } }); ``` Commented Sep 15, 2022 at 14:30
  • Doesn't $pull just take a value rather than an array? I can never remember how mongo operators work off the top of my head, but maybe remove the [] Commented Sep 15, 2022 at 14:34
  • Hm, lemme give it a try. Commented Sep 15, 2022 at 14:35

1 Answer 1

3

I think the correct syntax here is:

{
  $pull: {
    "AutoRole.Roles": value
  }
}
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.