【问题标题】:uncaught exception: SyntaxError: identifier starts immediately after numeric literal未捕获的异常:SyntaxError:标识符在数字文字之后立即开始
【发布时间】:2021-07-11 15:01:33
【问题描述】:
我创建了一个新集合:
db.createCollection("1st_Year_Students")
我正在尝试向此集合添加一个对象:
db.1st_Year_Students.insert({FullName : "Test Test"})
我遇到了这个错误:
未捕获的异常:SyntaxError:标识符在之后立即开始
数字文字:@(shell):1:2
【问题讨论】:
标签:
mongodb
mongodb-query
【解决方案1】:
Mongo Shell 无法识别集合名称,因为它从数字开始并导致错误,
Restriction on Collection Names:
如果您的集合名称包含特殊字符(例如下划线字符)或以数字开头,则要访问该集合,请使用 mongo shell 中的 db.getCollection() 方法或您的驱动程序的类似方法。 em>
db.getCollection('1st_Year_Students').insert({FullName : "Test Test"})