How to delete a field in mongoDB discord.js v13

Viewed 19

I have 5 fields in my document. I want to turn this,

  autoRole1: {
    type: String
  },
  autoRole2: {
    type: String
  },
  autoRole3: {
    type: String
  },
  autoRole4: {
    type: String
  },
  autoRole5: {
    type: String
  }

To this(for example):

  autoRole1: {
    type: String
  },
  autoRole3: {
    type: String
  },
  autoRole4: {
    type: String
  },
  autoRole5: {
    type: String
  }

How can I do it? This is the code I've tried:

const Welcome = require('../../models/Guild');
Welcome.update({guildId: message.guild.id}, { $unset: { "autoRole1": 1 } }, { multi: false });
1 Answers

did you try it like below? source

Welcome.update({guildId: message.guild.id}, { $unset: { "autoRole1": "" } }, { multi: false });
Related