uncaught exception: SyntaxError: unexpected token: identifier :when trying to log into as an admin for mongo shell

Elizabeth picture Elizabeth · Sep 12, 2020 · Viewed 9k times · Source

I am following this tutorial

https://docs.nodebb.org/installing/os/windows/

I got thru most of it easily but when I go to login as an admin with this command:

mongo -u admin -p ojo --authenticationDatabase=admin

I get an error:

uncaught exception: SyntaxError: unexpected token: identifier :
@(shell):1:9

ojo is the password btw

the admin account was created and it shows up when you run show users

show users
{
        "_id" : "admin.admin",
        "userId" : UUID("e3c3df1d-f63d-48e3-ae65-b9cf03c86333"),
        "user" : "admin",
        "db" : "admin",
        "roles" : [
                {
                        "role" : "root",
                        "db" : "admin"
                }
        ],
        "mechanisms" : [
                "SCRAM-SHA-1",
                "SCRAM-SHA-256"
        ]
}
{
        "_id" : "admin.admin2",
        "userId" : UUID("0b87390b-2c08-4e21-9183-8a2406a9304e"),
        "user" : "admin2",
        "db" : "admin",
        "roles" : [
                {
                        "role" : "root",
                        "db" : "admin"
                }
        ],
        "mechanisms" : [
                "SCRAM-SHA-1",
                "SCRAM-SHA-256"
        ]
}

What am I doing incorrectly? Tried many attempts.

Answer

ATUL TIWAREE picture ATUL TIWAREE · Jan 17, 2022

Don't open mongo shell and enter the connection string.

You have to enter the connection string (e.g., mongo mongodb+srv://m999student:[email protected]/testdb) from the operating system command prompt

  1. Press win + r
  2. Type cmd
  3. Paste the connection string
  4. now you'll be prompted to enter password, enter it and that's all!