[SERVER-5002] Change prohibited character sets in database names Created: 17/Feb/12  Updated: 17/Jan/23  Resolved: 21/Sep/20

Status: Closed
Project: Core Server
Component/s: Admin, Storage
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: Randolph Tan Assignee: Backlog - Storage Execution Team
Resolution: Won't Do Votes: 5
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-4413 Mongodump segfaults on certain collec... Closed
Duplicate
is duplicated by SERVER-16855 Windows does not support ASCII contro... Closed
is duplicated by SERVER-19044 use same database name validation rul... Closed
is duplicated by SERVER-8118 serverStatus locks and recordStats ha... Closed
is duplicated by SERVER-16198 Collection name shouldn't start or en... Closed
Related
related to SERVER-4122 Validate database and collection name... Closed
related to SERVER-44504 Treat linefeeds (\n, etc.) as invalid... Backlog
is related to TOOLS-14 Mongodump handling characters in coll... Closed
Assigned Teams:
Storage Execution
Participants:
Case:

 Description   

We just had this discussion while doing a review on SERVER-4954



 Comments   
Comment by Jeremy Mikola [ 30/Jul/19 ]

Cross-referencing with a PHP ticket where the customer was surprised that the server was accepting newline characters in a database and collection name. It lead to a question about whether the server would allow other control characters, to which I believe the answer is "yes" (anything not explicitly listed in naming restrictions).

Comment by Sara Williamson [ 18/Dec/18 ]

Our new proposal is to escape the current prohibited database name characters.

Comment by Federico Grillini [ 15/Oct/15 ]

Whitespace shouldn't be accepted in collections names, expecially leading and trailing whitespace that can make debugging harder.

Comment by Thomas Rueckstiess [ 26/Apr/13 ]

It's possible to create a database containing a $ sign. But trying to insert into it fails:

MongoDB shell version: 2.2.4
connecting to: test
> use $CLUSTER
switched to db $CLUSTER
> show dbs
local	(empty)
> db.docs.insert({foo: "bar"})
cannot insert into reserved $ collection
> show dbs
$CLUSTER	(empty)
local	(empty)
> 
bye

This is because DataFileMgr::insert() checks for any $ sign in the namespace with NamespaceString::normal().

The behavior should be consistent, either allowing $ in db names or not.

Turning on profiling in such a db fails as well:

> db.setProfilingLevel(2)
{
	"was" : 0,
	"slowms" : 100,
	"errmsg" : "exception: invalid ns: $CLUSTER.system.profile",
	"code" : 10356,
	"ok" : 0
}

Comment by Daniel Pasette (Inactive) [ 17/Apr/13 ]

current restrictions, as of 2.2 are as follows (http://docs.mongodb.org/manual/reference/limits/#naming-restrictions):

Restrictions on Database Names
The dot (i.e. .) character is not permissible in database names.

Database names are case sensitive even if the underlying file system is case insensitive.

In 2.2 and above the following characters are not permissible in database names:

/\. "*<>:|?

Restriction on Collection Names
New in version 2.2.

Collection names should begin with an underscore or a letter character, and cannot:

contain the $. be an empty string (e.g. "").
contain the null character.
begin with the system. prefix. (Reserved for internal use.)

Comment by Eliot Horowitz (Inactive) [ 18/Feb/12 ]

we should and do limit db names a bit - could do more

Comment by Greg Studer [ 17/Feb/12 ]

Mathias's comment was that b/c database names are actually used in data files, they should be more restricted than collection names. In particular, what happens when database names contain invalid file name characters on particular OSes is an issue.

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