Constraints for collection names

XMLWordPrintableJSON

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

      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
            Reporter:
            Uladzimir Mihura (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: