Skip to content

Commit 77c7a2e

Browse files
author
Chris Cho
committed
starts-with and ends-before
1 parent 9b6d938 commit 77c7a2e

9 files changed

+43
-17
lines changed

source/code-snippets/collation/aggregation-collation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
Retrieve the total number of matching names, grouped by the first_name
33
field and sorted by using the German phonebook collation.
44
*/
5+
// start aggregation collation
56
myColl.aggregate(
67
[
78
{ $group: { "_id": "$first_name", "nameCount": { "$sum": 1 } } },
89
{ $sort: { "_id": 1 } },
910
],
1011
{ collation: { locale: "de@collation=phonebook" } },
1112
);
13+
// end aggregation collation
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
// Retrieve documents that match "photograph" in the "type" field
2-
myColl.find({type: "photograph"});
2+
// start auto collation
3+
myColl.find({type: "photograph"});
4+
// end auto collation
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Create the "souvenirs" collection and specify the French Canadian collation
2+
// start collection collation
23
db.createCollection("souvenirs", {
34
collation: { locale: "fr_CA" },
4-
});
5+
});
6+
// end collection collation

source/code-snippets/collation/collection-specify-collation.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Retrieve documents that match "photograph" in the "type" field,
33
sorted by the Iceland collation and uppercase precedence.
44
*/
5+
// start specified collation
56
myColl.find({type: "photograph"},
67
{ collation: { locale: "is", caseFirst: "upper" } }
78
);
8-
9+
// end specified collation

source/code-snippets/collation/findOneAndUpdate-collation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
that precedes "Gunter" when ordered by using the
44
German phonebook collation order.
55
*/
6+
// start findOneAndUpdate collation
67
myColl.findOneAndUpdate(
78
{ first_name: { $lt: "Gunter" } },
89
{ $set: { verified: true } },
910
{ collation: { locale: "de@collation=phonebook" } },
10-
);
11+
);
12+
// end findOneAndUpdate collation

source/code-snippets/collation/index-collation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
locale collation, specifying ascending ordering of the
44
"title" field.
55
*/
6+
// start index collation
67
myColl.createIndex(
78
{ 'title' : 1 },
89
{ 'collation' : { 'locale' : 'en_US' } });
10+
// end index collation

source/code-snippets/collation/query-index-no-collation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Retrieve documents that match the "year" value "1980"
33
in descending order of the value of the "title" field
44
that does not use the collation index.
5-
*/
5+
*/
6+
// start index no collation
67
myColl.find({"year": 1980})
78
.sort({"title": -1});
9+
// end index no collation

source/code-snippets/collation/query-not-indexed-collation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
specifying a collation that does not use the collation
55
index.
66
*/
7+
// start not indexed collation
78
myColl.find({"year": 1980}, {"collation" : {"locale" : "en_US", "strength": 2 }})
8-
.sort({"title": -1});
9+
.sort({"title": -1});
10+
// end not indexed collation

source/fundamentals/collations.txt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,26 @@ collection.
120120

121121
.. literalinclude:: /code-snippets/collation/collection-collation.js
122122
:language: javascript
123-
:lineno-start: 2
123+
:start-after: start collection collation
124+
:ends-before: end collection collation
124125

125126
Any of the operations that support collations automatically apply the collation
126127
defined on the collection. The query below searches the ``souvenirs``
127128
collection and applies the "``fr_CA``" locale collation:
128129

129130
.. literalinclude:: /code-snippets/collation/collection-auto-collation.js
130131
:language: javascript
131-
:lineno-start: 2
132+
:start-after: start auto collation
133+
:ends-before: end auto collation
132134

133135
You can specify a different collation as a parameter in an operation that
134136
supports collations. The following query specifies the "``is``" Iceland locale
135137
and ``caseFirst`` optional parameter with the value "``upper``":
136138

137139
.. literalinclude:: /code-snippets/collation/collection-specify-collation.js
138140
:language: javascript
139-
:lineno-start: 5
141+
:start-after: start specified collation
142+
:ends-before: end specified collation
140143

141144
Assign a Collation to an Index
142145
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -146,25 +149,27 @@ a collection with a collation set to the "``en_US``" locale.
146149

147150
.. literalinclude:: /code-snippets/collation/index-collation.js
148151
:language: javascript
149-
:lineno-start: 5
152+
:start-after: start indexcollation
153+
:ends-before: end indexcollation
150154

151155
The following query uses the index we created:
152156

153157
.. literalinclude:: /code-snippets/collation/query-index-collation.js
154158
:language: javascript
155-
:lineno-start: 6
156159

157160
The following queries **do not** use the index that we created. The first
158161
query does not include a collation and the second contains a different
159162
strength value than the collation on the index.
160163

161164
.. literalinclude:: /code-snippets/collation/query-not-indexed-collation.js
162165
:language: javascript
163-
:lineno-start: 6
166+
:start-after: start not indexed collation
167+
:ends-before: end not indexed collation
164168

165169
.. literalinclude:: /code-snippets/collation/query-index-no-collation.js
166170
:language: javascript
167-
:lineno-start: 6
171+
:start-after: start index no collation
172+
:ends-before: end index no collation
168173

169174
Collation Query Examples
170175
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -203,7 +208,8 @@ which **does not** specify a collation:
203208

204209
.. literalinclude:: /code-snippets/collation/findOneAndUpdate-default-order-collation.js
205210
:language: javascript
206-
:lineno-start: 6
211+
:start-after: start findOneAndUpdate collation
212+
:ends-before: end findOneAndUpdate collation
207213

208214
Since "Gunter" is the first sorted result when using a binary collation, none
209215
of the documents come lexically before and match the ``$lt`` comparison
@@ -219,7 +225,8 @@ umlauts.
219225

220226
.. literalinclude:: /code-snippets/collation/findOneAndUpdate-collation.js
221227
:language: javascript
222-
:lineno-start: 6
228+
:start-after: start findOneAndUpdate default order collation
229+
:ends-before: end findOneAndUpdate default order collation
223230

224231
Since "Günter" lexically comes before "Gunter" using the
225232
``de@collation=phonebook`` collation specified in ``findOneAndUpdate()``,
@@ -250,7 +257,8 @@ lexical order.
250257

251258
.. literalinclude:: /code-snippets/collation/findOneAndDelete-collation.js
252259
:language: javascript
253-
:lineno-start: 6
260+
:start-after: start findOneAndDelete collation
261+
:ends-before: end findOneAndDelete collation
254262

255263
After you run the operation above, the collection contains the following
256264
documents:
@@ -267,7 +275,8 @@ document it finds that matches the query criteria.
267275

268276
.. literalinclude:: /code-snippets/collation/findOneAndDelete-no-collation.js
269277
:language: javascript
270-
:lineno-start: 6
278+
:start-after: start findOneAndDelete no collation
279+
:ends-before: end findOneAndDelete no collation
271280

272281
Since all the documents contain lexical values in the ``a`` field that
273282
match the criteria (greater than the lexical value of "``100``"), the operation
@@ -297,3 +306,5 @@ the German phonebook (``de@collation=phonebook`` locale) order.
297306

298307
.. literalinclude:: /code-snippets/collation/aggregation-collation.js
299308
:language: javascript
309+
:start-after: start aggregation collation
310+
:ends-before: end aggregation collation

0 commit comments

Comments
 (0)