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?

1
  • 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. Commented Aug 4, 2015 at 13:01

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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("_")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.