简体   繁体   中英

How to remove a element from an Array in Mongoose/MongoDB?

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.

I think the correct syntax here is:

{
  $pull: {
    "AutoRole.Roles": value
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM