diff --git a/source/includes/fact-case-sensitivity-limitation-code.rst b/source/includes/fact-case-sensitivity-limitation-code.rst new file mode 100644 index 00000000000..ea35a2174af --- /dev/null +++ b/source/includes/fact-case-sensitivity-limitation-code.rst @@ -0,0 +1,31 @@ + +.. example:: + + If the database ``salesDB`` already exists MongoDB will + return an error if if you attempt to create a database named ``salesdb``. + + .. code-block:: javascript + + mixedCase = db.getSiblingDB('salesDB') + lowerCase = db.getSiblingDB('salesdb') + + mixedCase.retail.insertOne({ "widgets": 1, "price": 50 }) + + The operation succeeds and :method:`~db.collection.insertOne()` implicitly + creates the ``SalesDB`` database. + + .. code-block:: javascript + + lowerCase.retail.insertOne({ "widgets": 1, "price": 50 }) + + The operation fails. :method:`~db.collection.insertOne()` tries to + create a ``salesdb`` database and is blocked by the naming + restriction. Database names must differ on more than just case. + + .. code-block:: javascript + + lowerCase.retail.find() + + This operation does not return any results because the database names are case + sensitive. There is no error because :method:`~db.collection.find()` doesn't + implicitly create a new database. \ No newline at end of file diff --git a/source/reference/limits.txt b/source/reference/limits.txt index 79d7c45ac32..154f673564e 100644 --- a/source/reference/limits.txt +++ b/source/reference/limits.txt @@ -36,8 +36,11 @@ Naming Restrictions .. limit:: Database Name Case Sensitivity - Since database names are case *insensitive* in MongoDB, database - names cannot differ only by the case of the characters. + Database names are case-sensitive in MongoDB. They also have an + additional restriction, case cannot be the only difference between + database names. + + .. include:: /includes/fact-case-sensitivity-limitation-code.rst .. limit:: Restrictions on Database Names for Windows