uncaught exception: SyntaxError: identifier starts immediately after numeric literal

Viewed 452

I have created a new collection :

db.createCollection("1st_Year_Students")

I am trying to add an object to this collection :

db.1st_Year_Students.insert({FullName : "Test Test"})

I am having this error :

uncaught exception: SyntaxError: identifier starts immediately after numeric literal : @(shell):1:2

1 Answers

Mongo Shell does not recognise the collection name because its started from number and causes the error,

Restriction on Collection Names:

If your collection name includes special characters, such as the underscore character, or begins with numbers, then to access the collection use the db.getCollection() method in the mongo shell or a similar method for your driver.

db.getCollection('1st_Year_Students').insert({FullName : "Test Test"})
Related