0

I have modified a schema (ie, users) by deleting a key (ie, ips). Thus I want to delete this key in all the documents in the database.

For example, in mongo console or Robo 3T, db.getCollection('users').find({}) returns all the users. Some of them contain the key ips. Does anyone know how to remove ips in the console or Robo 3T?

SoftTimur
  • 7,806
  • 30
  • 123
  • 245

2 Answers2

2

Update Multiple Documents

To update multiple documents, set the multi option to true. Refer here

db.getCollection('users').update(
  { },
  { $unset: { ips: 1 } },
  { multi: true } 
)
Community
  • 1
  • 1
codejockie
  • 7,478
  • 3
  • 37
  • 43
1

As @Veeram already posted you can run a regular update with $unset just add multi: true in the options to update all documents, otherwise it will update just one

db.users.update(
  { }, // where
  { $unset: { ips: 1 } }, // change what
  { multi: true } // options
)
Zilvinas
  • 5,319
  • 3
  • 23
  • 26