I have a collection of documents stored in a MongoDB database that looks like this:
[
  {
    _id: 5fe72e02b237503088b8889b,
    code: '000001403',
    name: 'John',
    date: 2018-12-01T21:00:00.000Z,
    __v: 1
  },
  {
    _id: 5fe72e02b237503088b8889c,
    code: '000001404',
    name: 'Michael',
    date: 2018-12-01T21:00:00.000Z,
    __v: 1
  }
]
I need to remove the "code" field from all documents in the collection and keep the documents, that is, I need the following result:
[
  {
    _id: 5fe72e02b237503088b8889b,
    name: 'John',
    date: 2018-12-01T21:00:00.000Z,
    __v: 1
  },
  {
    _id: 5fe72e02b237503088b8889c,
    name: 'Michael',
    date: 2018-12-01T21:00:00.000Z,
    __v: 1
  }
]
I also removed the field from the model:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ItemSchema = new Schema({
  // code: String,
  name: String,
  date: {
    type: Date,
    default: Date.now
  },
});
module.exports = mongoose.model('Item', ItemSchema);
I don't know if it is possible to use aggregation and the $unset method in this case, or is there another method?
Thanks.
 
    