Home > OS >  Cannot create collection on Mongo
Cannot create collection on Mongo

Time:11-25

I am trying to create collection on terminal using mongo shell. if I run

db_name> db.createCollection("system.indexes");

it outputs this error

MongoServerError: Invalid system namespace: db_name.system.indexes

What am I doing wrong?

CodePudding user response:

Collection names cannot begin with the system. prefix. Please see the full list of namespace limitations.

https://docs.mongodb.com/manual/reference/limits/#std-label-faq-restrictions-on-collection-names

CodePudding user response:

Create Collection using below query :

db.createCollection( "contacts", {
      validator: { $jsonSchema: {
      properties: {
    user_id: {
            type: "number",
            description: "must be a number and is required"
         }
      }
    }}
} )
  • Related