You need to specify the database permissions for the login account.

If the "Authentication failed" message is displayed while you run the following command to connect to your ApsaraDB for MongoDB instance with the account that you created in the instance (both the username and password are test), see the following explanations:

mongo --host $myhost --port $myport -u test -p test

In ApsaraDB for MongoDB, an account is authorized for certain databases. To be authenticated when you connect to an ApsaraDB for MongoDB instance, you must specify the database where your account is created. For example, the test account is created in the admin database. You can run the following command to connect to your instance:

mongo --host $myhost --port $myport -u test -p test --authenticationDatabase admin

Or you can run the following commands:

    mongo --host $myhost --port $myport
    mongo> use admin
    mongo> db.auth("test", "test")