George Jor
George Jor

Reputation: 511

Cannot update mongodb record

When I try to execute the following command:

db.users.update(
   { _id: 5392beaf0e50cfe50a781e19 }, 
   { $set: { 'role': 'admin' }
})

I got the following errors:

Sat Jun  7 16:24:58.798 SyntaxError: Unexpected token ILLEGAL

What's going on?

Upvotes: 0

Views: 256

Answers (1)

Neil Lunn
Neil Lunn

Reputation: 151220

You need to cast an ObjectId and your JSON syntax is also illegal:

db.users.update(
   { _id: ObjectId("5392beaf0e50cfe50a781e19") }, 
   { $set: { 'role': 'admin' }
})

Upvotes: 1

Related Questions