获取MongoDB错误 - SyntaxError:意外的令牌?

时间:2015-08-04 11:15:31

标签: mongodb nosql

我是一个Mongo数据库。有一个名为_migrations的集合。我正在尝试将几个文档插入到集合中。但是我收到以下错误SyntaxError: Unexpected token ?。我的代码如下。

db._migrations.insert([
{
  "_id" : "1_create-organization-collection"
},
{
  "_id" : "2_create-dataFilter-collection"
},
{
  "_id" : "3_create-application-collection"
},
{
  "_id" : "4_migrate-datafilters-to-mongo"
},
{
  "_id" : "5_Add-Salesforce-DataFilters"
},
{
  "_id" : "6_biq-repository-data-fiter"
}]);

我做错了什么?

3 个答案:

答案 0 :(得分:1)

您可以尝试删除收藏品名称中的下划线(“”)吗?我尝试使用下划线,但它对我不起作用,但是当我尝试没有下划线(“”)时,插入了相同的数据。因此,请在您的收藏名称中尝试不带下划线。

答案 1 :(得分:1)

在使用ObjectId的类型case之后可以插入

_id字段值。它会像下面这样工作 -

 db._migrations.insert([
   { "_id" : ObjectId("1_create-organization-collection") },  
   { "_id" : ObjectId("2_create-dataFilter-collection") }
 ]);

答案 2 :(得分:1)

有关此问题的详情,请参阅以下链接:

Is there a convention to name collection in MongoDB?

Mongo client can't access collections prefixed with an underscore

Mongo shell不支持以下划线开头的集合名称(" _")

相关问题