Rajesh Kumar Dash
Rajesh Kumar Dash

Reputation: 2277

How to avoid SyntaxError: missing : after property id @(shell):1:36 on mongoDb?

I am new to mongodb and just started with mongodb .I am writingto grant roles to user but throw SyntaxError: missing : after property id @(shell):1:36.Tried removing space but did not workout .

db.grantRolesToUser(
{
"user",
roles: [{
"role" : "readWrite",
"db" : "chatlogging"
},
{ role: "userAdminAnyDatabase", db: "admin"}]
}
)

Any clue on this .Thanks in advance.

Upvotes: 2

Views: 2083

Answers (2)

Ashish
Ashish

Reputation: 643

As per the documentation (https://docs.mongodb.com/manual/reference/method/db.grantRolesToUser/) you don't need to specify roles as key in command, try following

db.grantRolesTouser(
    "user",
    [
       {
            "role": "readWrite",
            "db": "chatlogging"
        },
        {
            "role": "userAdminAnyDatabase",
            "db": "admin"
        }
    ]
)

Upvotes: 0

RidgeA
RidgeA

Reputation: 1546

you put a redundant curly bracket

the command should be like

db.grantRolesToUser(
 "user",
 [
  {"role" : "readWrite", "db" : "chatlogging"},
  {"role" : "userAdminAnyDatabase", "db": "admin"}
 ]
)

refer to the documentation https://docs.mongodb.com/manual/reference/method/db.grantRolesToUser/

Upvotes: 3

Related Questions