To prevent this type of hack, you need to make your database secure.
Add the security.authorization parameter to the configuration file
security: authorization: enabled
Before turning on, make sure you create a root user with login credentials.
Example:
$ use admin $ db.createUser( { user: "superAdmin", pwd: "mySecurePassword", roles: [ { role: "root", db: "admin" } ] })
you may also need to create a separate application for each database with limited access, for more information I wrote one blog here MongoDB enable authentication .
for more information, see the MongoDB Security Best Practices and MongoDB Security Checklist
source share