[SERVER-4394] Constraints for collection names Created: 30/Nov/11  Updated: 10/Dec/14  Resolved: 13/Mar/13

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Uladzimir Mihura Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

ALL


Participants:

 Description   

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.



 Comments   
Comment by Uladzimir Mihura [ 13/Mar/13 ]

Tried with master brach too:

> db.createCollection("$test")
{ "errmsg" : "exception: invalid ns: test.$test", "code" : 10356, "ok" : 0 }
> db.getCollectionNames()
[ ]
> db.createCollection("имя")
{ "ok" : 1 }
> db.getCollectionNames()
[ "system.indexes", "имя" ]
> db.dropDatabase()
{ "dropped" : "test", "ok" : 1 }
> db.createCollection("tmp")
{ "ok" : 1 }
> db.tmp.renameCollection("имя")
{ "ok" : 1 }
> db.getCollectionNames()
[ "system.indexes", "имя" ]
> db.имя.insert({"test":1})
> db.getCollectionNames()
[ "system.indexes", "имя" ]
> db.имя2.insert({"test":1})
> db.getCollectionNames()
[ "system.indexes", "имя", "имя2" ]
> db.имя.drop()
true
> db.getCollectionNames()
[ "system.indexes", "имя2" ]
> db.имя2.drop()
true
> db.getCollectionNames()
[ "system.indexes" ]
> 

No issues. Ticket can be closed.

Thank you Tad!

-vova

Comment by Tad Marshall [ 11/Mar/13 ]

Testing these cases in Windows in today's master branch, I can't duplicate any of the bugs.

There seems to be some confusion between capital and small Cyrillic collection names in the last case; he tries to drop a "capital" name, gets "false" (not dropped) and sees that a "small" one still exists.

Comments are from Unicode document ISO10646-01-0000-33FF.pdf:

> var name1 = "ИМЯ"
> var name2 = "имя"
> for (var i=0; i<name1.length; ++i) {print(name1.charCodeAt(i))}
1048    // 0418 И CYRILLIC CAPITAL LETTER I
1052    // 041C М CYRILLIC CAPITAL LETTER EM
1071    // 042F Я CYRILLIC CAPITAL LETTER YA
> for (var i=0; i<name2.length; ++i) {print(name2.charCodeAt(i))}
1080    // 0438 и CYRILLIC SMALL LETTER I
1084    // 043C м CYRILLIC SMALL LETTER EM
1103    // 044F я CYRILLIC SMALL LETTER YA

We don't do case folding on collection names.

> db.getCollectionNames()
[ "system.indexes" ]
> db.FOO.insert({a:1})
> db.foo.insert({b:1})
> db.getCollectionNames()
[ "FOO", "foo", "system.indexes" ]

I agree, this seems closable.

Generated at Thu Feb 08 03:05:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.