|
| 1 | +.. _collation-collection: |
| 2 | + |
| 3 | +================================== |
| 4 | +Create a Collection with Collation |
| 5 | +================================== |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +:manual:`Collation </reference/collation/>` allows you to specify |
| 16 | +language-specific rules for string comparison, such as rules for lettercase |
| 17 | +and accent marks. |
| 18 | + |
| 19 | +Procedure |
| 20 | +--------- |
| 21 | + |
| 22 | +.. procedure:: |
| 23 | + :style: connected |
| 24 | + |
| 25 | + .. step:: Click the :guilabel:`Create Collection` button. |
| 26 | + |
| 27 | + From the :guilabel:`Collections` screen, click the |
| 28 | + :guilabel:`Create Collection` button. |
| 29 | + |
| 30 | + .. step:: Enter the collection name. |
| 31 | + |
| 32 | + .. step:: Click the :guilabel:`Advanced Collection Options` dropdown. |
| 33 | + |
| 34 | + Check the :guilabel:`Use Custom Collaton` option. |
| 35 | + |
| 36 | + .. step:: Select a value for :guilabel:`locale`. |
| 37 | + |
| 38 | + You are required to select a :guilabel:`locale` from the :manual:`MongoDB |
| 39 | + supported languages </reference/collation-locales-defaults/#supported-languages-and-locales>`. |
| 40 | + |
| 41 | + All other collation options parameters are optional. For descriptions of |
| 42 | + the fields, see :manual:`Collation </reference/collation/>`. |
| 43 | + |
| 44 | + .. step:: Click :guilabel:`Create Collection` to create the collection. |
| 45 | + |
| 46 | +Restrictions and Limitations |
| 47 | +---------------------------- |
| 48 | + |
| 49 | +The following restrictions apply when the parameter ``numericOrdering`` |
| 50 | +is set to ``true``: |
| 51 | + |
| 52 | +- Only contiguous non-negative integer substrings of digits are |
| 53 | + considered in the comparisons. ``numericOrdering`` does not support: |
| 54 | + |
| 55 | + - ``+`` |
| 56 | + - ``-`` |
| 57 | + - exponents |
| 58 | + |
| 59 | +- Only Unicode code points in the Number or Decimal Digit (Nd) category |
| 60 | + are treated as digits. |
| 61 | + |
| 62 | +- If the number length exceeds 254 characters, the excess characters are |
| 63 | + treated as a separate number. |
| 64 | + |
| 65 | +Example |
| 66 | +~~~~~~~ |
| 67 | + |
| 68 | +Consider a collection with the following string number and decimal values: |
| 69 | + |
| 70 | +.. code-block:: javascript |
| 71 | + |
| 72 | + [ |
| 73 | + { "n": "1" }, |
| 74 | + { "n": "2" }, |
| 75 | + { "n": "-2.1" }, |
| 76 | + { "n": "2.0" }, |
| 77 | + { "n": "2.20" }, |
| 78 | + { "n": "10"}, |
| 79 | + { "n": "20" }, |
| 80 | + { "n": "20.1" }, |
| 81 | + { "n": "-10" }, |
| 82 | + { "n": "3" } |
| 83 | + ] |
| 84 | + |
| 85 | +The following find query uses a collation document containing the |
| 86 | +``numericOrdering`` parameter: |
| 87 | + |
| 88 | +.. code-block:: javascript |
| 89 | + |
| 90 | + db.c.find( |
| 91 | + { }, { _id: 0 } |
| 92 | + ).sort( |
| 93 | + { n: 1 } |
| 94 | + ).collation( { |
| 95 | + locale: 'en_US', |
| 96 | + numericOrdering: true |
| 97 | + } ) |
| 98 | + |
| 99 | +For more information on querying documents in |compass-short|, see |
| 100 | +:ref:`Query Your Data <compass-query-bar>`. |
| 101 | + |
| 102 | +The operations returns the following results: |
| 103 | + |
| 104 | +.. code-block:: javascript |
| 105 | + :emphasize-lines: 2, 3 |
| 106 | + |
| 107 | + [ |
| 108 | + { "n": "-2.1" }, |
| 109 | + { "n": "-10" }, |
| 110 | + { "n": "1" }, |
| 111 | + { "n": "2" }, |
| 112 | + { "n": "2.0" } |
| 113 | + { "n": "2.20" }, |
| 114 | + { "n": "3" }, |
| 115 | + { "n": "10" }, |
| 116 | + { "n": "20" }, |
| 117 | + {"n": "20.1" } |
| 118 | + ] |
| 119 | + |
| 120 | +- ``numericOrdering: true`` sorts the string values in ascending order as if |
| 121 | + they were numeric values. |
| 122 | + |
| 123 | +- The two negative values ``-2.1`` and ``-10`` are not sorted in the |
| 124 | + expected sort order because they have unsupported ``-`` characters. |
0 commit comments