Mass update users email with api or mongodb script

Description

Hi,
Is it possible to update users’ email addresses in bulk? For example, we changed the domain in the organization, and we need to change the email address in rocketchat for all users from “xxx@example.com” to “xxx@neworg.com”. Only domain part is changed. It is tedious to do this through the admin panel, for 50+ users. Mb someone provide a solution in the form of a script? Thank you.

Server Setup Information

  • Version of Rocket.Chat Server: 4.8
  • Operating System: centos
  • Deployment Method: docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog:
  • NodeJS Version:
  • MongoDB Version:
  • Proxy:
  • Firewalls involved:

Hi! Welcome to our community!!

You can easily do that consuming two APIs. this one to get the user list:

you will then iterate over each record, and use this other API to update it:

You can do it also directly in mongodb, we don’t recommend updating the DB directly.

If you want to use python for it, I recommend the awesome Lib that will save you some lines:

Well, yes, at the beginning I tried to update via api, but something didn’t work out for me. :smiley:
As a result, I updated directly via mongoexport/import.
Thanks for the help!