Skip to content

Commit 70a922c

Browse files
author
Chris Cho
committed
PRR fixes 2
1 parent fc13bf4 commit 70a922c

8 files changed

+51
-61
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Retrieve documents that match "photograph" in the "type" field
2+
myColl.find({type: "photograph"});
Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
1-
// start create collection with collation
2-
// Create the "souvenirs" collection and specify the French Canadian collation.
1+
// Create the "souvenirs" collection and specify the French Canadian collation
32
db.createCollection("souvenirs", {
43
collation: { locale: "fr_CA" },
5-
});
6-
// end create collection with collation
7-
8-
// start collection query without collation
9-
// Retrieve documents that match "photograph" in the "type" field.
10-
myColl.find({type: "photograph"});
11-
// end collection query without collation
12-
13-
// start collection query with collation
14-
/*
15-
Retrieve documents that match "photograph" in the "type" field,
16-
sorted by the Iceland collation and uppercase precedence.
17-
*/
18-
myColl.find({type: "photograph"},
19-
{ collation: { locale: "is", caseFirst: "upper" } }
20-
);
21-
// end collection query with collation
4+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Retrieve documents that match "photograph" in the "type" field,
3+
sorted by the Iceland collation and uppercase precedence.
4+
*/
5+
myColl.find({type: "photograph"},
6+
{ collation: { locale: "is", caseFirst: "upper" } }
7+
);
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
Update the "verified" field to "true" for the first document
3+
that precedes "Gunter" when ordered by using the
4+
default binary collation order.
5+
*/
6+
myColl.findOneAndUpdate(
7+
{ first_name : { $lt: "Gunter" } },
8+
{ $set: { verified: true } }
9+
);
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
// start query index collation
21
/*
32
Retrieve documents that match the "year" value "1980"
43
in descending order of the value of the "title" field,
54
specifying a collation that uses the index.
65
*/
76
myColl.find({"year": 1980}, {"collation" : {"locale" : "en_US" }})
8-
.sort({"title": -1});
9-
// end query index collation
10-
11-
// start query without index collation
12-
/*
13-
Retrieve documents that match the "year" value "1980"
14-
in descending order of the value of the "title" field
15-
that does not use the collation index.
16-
*/
17-
myColl.find({"year": 1980})
18-
.sort({"title": -1});
19-
20-
/*
21-
Retrieve documents that match the "year" value "1980"
22-
in descending order of the value of the "title" field,
23-
specifying a collation that does not use the collation
24-
index.
25-
*/
26-
myColl.find({"year": 1980}, {"collation" : {"locale" : "en_US", "strength": 2 }})
27-
.sort({"title": -1});
28-
// end query without index collation
7+
.sort({"title": -1});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
Retrieve documents that match the "year" value "1980"
3+
in descending order of the value of the "title" field
4+
that does not use the collation index.
5+
*/
6+
myColl.find({"year": 1980})
7+
.sort({"title": -1});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Retrieve documents that match the "year" value "1980"
3+
in descending order of the value of the "title" field,
4+
specifying a collation that does not use the collation
5+
index.
6+
*/
7+
myColl.find({"year": 1980}, {"collation" : {"locale" : "en_US", "strength": 2 }})
8+
.sort({"title": -1});

source/fundamentals/collations.txt

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

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

126125
Any of the operations that support collations automatically apply the collation
127126
defined on the collection. The query below searches the ``souvenirs``
128127
collection and applies the "``fr_CA``" locale collation:
129128

130-
.. literalinclude:: /code-snippets/collation/collection-collation.js
129+
.. literalinclude:: /code-snippets/collation/collection-auto-collation.js
131130
:language: javascript
132-
:start-after: start collection query without collation
133-
:end-before: end collection query without collation
131+
:lineno-start: 2
134132

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

139-
.. literalinclude:: /code-snippets/collation/collection-collation.js
137+
.. literalinclude:: /code-snippets/collation/collection-specify-collation.js
140138
:language: javascript
141-
:start-after: start collection query with collation
142-
:end-before: end collection query with collation
139+
:lineno-start: 5
143140

144141
Assign a Collation to an Index
145142
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -155,20 +152,19 @@ The following query uses the index we created:
155152

156153
.. literalinclude:: /code-snippets/collation/query-index-collation.js
157154
:language: javascript
158-
:start-after: start query index collation
159-
:end-before: end query index collation
160-
:emphasize-lines: 6-7
161-
155+
:lineno-start: 6
162156

163157
The following queries **do not** use the index that we created. The first
164158
query does not include a collation and the second contains a different
165159
strength value than the collation on the index.
166160

167-
.. literalinclude:: /code-snippets/collation/query-index-collation.js
161+
.. literalinclude:: /code-snippets/collation/query-index-not-indexed-collation.js
168162
:language: javascript
169-
:start-after: start query without index collation
170-
:end-before: end query without index collation
163+
:lineno-start: 6
171164

165+
.. literalinclude:: /code-snippets/collation/query-index-no-collation.js
166+
:language: javascript
167+
:lineno-start: 6
172168

173169
Collation Query Examples
174170
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -205,10 +201,9 @@ following documents:
205201
Consider the following ``findOneAndUpdate()`` operation on this collection
206202
which **does not** specify a collation:
207203

208-
.. literalinclude:: /code-snippets/collation/findOneAndUpdate-collation.js
204+
.. literalinclude:: /code-snippets/collation/findOneAndUpdate-default-order-collation.js
209205
:language: javascript
210-
:start-after: start findOneAndUpdate without collation
211-
:end-before: end findOneAndUpdate without collation
206+
:lineno-start: 6
212207

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

225220
.. literalinclude:: /code-snippets/collation/findOneAndUpdate-collation.js
226221
:language: javascript
227-
:start-after: start findOneAndUpdate with collation
228-
:end-before: end findOneAndUpdate with collation
222+
:lineno-start: 6
229223

230224
Since "Günter" lexically comes before "Gunter" using the
231225
``de@collation=phonebook`` collation specified in ``findOneAndUpdate()``,

0 commit comments

Comments
 (0)