[SERVER-12976] Misleading error when inserting into collection with long name. Created: 28/Feb/14  Updated: 28/Oct/15  Resolved: 07/Mar/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.6.0-rc0
Fix Version/s: 2.6.0-rc2

Type: Bug Priority: Minor - P4
Reporter: A. Jesse Jiryu Davis Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

var collection_name = '';
while (collection_name.length < 127) {
    collection_name += 'a';
}
 
jsTest.log('collection name length: ' + collection_name.length);
 
db.collection.drop();
var result = db.runCommand({
    insert: collection_name,
    documents: [{}]
});
 
printjson(result);

Participants:

 Description   

Attempting to insert into a collection with a 127-character-long name fails, with the error message: "ns name too long, max size is 127 bytes". I seems it should actually say, "120 bytes."

If the length of the fully-qualified namespace (db + "." + collection) is at most 127 characters, we get a more accurate error, "fully qualified namespace db.<LONG-COLLECTION-NAME> is too long (max is 120 bytes)".

Another possible value is 123 bytes, documented here:

http://docs.mongodb.org/manual/reference/limits/



 Comments   
Comment by Githook User [ 07/Mar/14 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-12976 Check collection name length limit in userAllowedWriteNS

This should improve error messages for over-length collections. Previously
this would be checked before the collection would be created but depending on
the length, may generate a different error. It also resolves SERVER-13074 and
SERVER-13075.
Branch: master
https://github.com/mongodb/mongo/commit/a1977962b7a1fccdd60d31ab3c27bb51bd3d6156

Comment by Mathias Stearn [ 06/Mar/14 ]

It's a bit complicated. Namespaces are limited to 127 bytes, but collections are limited to 120 since each collection also gets an db.collection.$extra namespace that also needs to fit under the 127 byte limit. I'll see what I can do about making the error better here.

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