Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-4394

Constraints for collection names

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      ALL

      In the http://www.mongodb.org/display/DOCS/Collections

      Collection names should begin with letters or an underscore and may include numbers; $ is reserved.

      Use $ in name:

      > db.dropDatabase()
      > db.createCollection("$test")
      { "ok" : 1 }
      > db.getCollectionNames()
      [ "system.indexes"]
      > db.createCollection("$test")
      { "errmsg" : "collection already exists", "ok" : 0 }
      

      Use UTF-8 characters when creating collection:

      > db.getCollectionNames()
      [ "system.indexes" ]
      > db.createCollection("имя")
      {
      	"errmsg" : "exception: invalid ns: query-test.имя.$_id_",
      	"code" : 10094,
      	"ok" : 0
      }
      > db.getCollectionNames()
      [ "system.indexes", "имя" ]
      

      Use UTF-8 characters when renaming collection:

      > db.dropDatabase()
      { "dropped" : "query-test", "ok" : 1 }
      > db.createCollection("tmp")
      { "ok" : 1 }
      > db.tmp.renameCollection("имя")
      { "ok" : 1 }
      > db.getCollectionNames()
      [ "system.indexes", "имя" ]
      

      Inserting into collection with name in UTF-8:

      > db.ИМЯ.insert({"test":1})
      invalid ns: query-test.ИМЯ
      > db["ИМЯ"].insert({"test":1})
      invalid ns: query-test.ИМЯ
      

      Dropping collection with name in UTF-8:

      > db.ИМЯ.drop()
      false
      > db.getCollectionNames()
      [ "system.indexes", "имя" ]
      

      In Java, Python and PHP it is impossible to create collection with name in UTF-8, but it's possible to use such characters in rename and drop.

            Assignee:
            Unassigned Unassigned
            Reporter:
            uladzimir_mihura@epam.com Uladzimir Mihura
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: