0

I am a Mongo database. There is a collection called _migrations. I am trying to insert couple of documents into the collection. But I am getting the following error SyntaxError: Unexpected token ?. My code is below.

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"
}]);

What am I doing wrong?

halfer
  • 19,824
  • 17
  • 99
  • 186
odbhut.shei.chhele
  • 5,834
  • 16
  • 69
  • 109
  • Thank you for all your answers. I have solved the issue. The problem was when I was pasting it in the shell, an extra space character was being inserted after the square brackets. After removing the extra space, the code is working fine. – odbhut.shei.chhele Aug 04 '15 at 13:01

3 Answers3

1

Can you please trying removing underscore("") in your collection name? I tried with underscore but it did not work for me, but when I tried without underscore("") same data got inserted. So, please try without underscore in your collection name.

Abie
  • 624
  • 5
  • 12
1

_id field value can be inserted after type case with ObjectId. it will work like below -

 db._migrations.insert([
   { "_id" : ObjectId("1_create-organization-collection") },  
   { "_id" : ObjectId("2_create-dataFilter-collection") }
 ]);
Vishnu Atrai
  • 2,370
  • 22
  • 24
1

Please refer below links for more details about the issue:

Is there a convention to name collection in MongoDB?

Mongo client can't access collections prefixed with an underscore

Mongo shell does not support collection name starting with underscore("_")

Community
  • 1
  • 1
Abie
  • 624
  • 5
  • 12