Skip to content

Commit 1d77175

Browse files
author
Chris Cho
committed
DOCSP-32718: add CodeWhisperer comments to collation code snippets
1 parent f09e867 commit 1d77175

File tree

8 files changed

+53
-2
lines changed

8 files changed

+53
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Retrieve the total matching names, grouped by the first_name field and sorted by using the German phonebook collation
12
myColl.aggregate(
23
[
34
{ $group: { "_id": "$first_name", "nameCount": { "$sum": 1 } } },

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
// start create collection with collation
2-
// Create the collection with a collation
2+
// Create the "souvenirs" collection and specify the French Canadian collation.
33
db.createCollection("souvenirs", {
44
collation: { locale: "fr_CA" },
55
});
66
// end create collection with collation
77

88
// start collection query without collation
9+
// Retrieve documents that match "photograph" in the "type" field.
910
myColl.find({type: "photograph"});
1011
// end collection query without collation
1112

1213
// 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+
*/
1318
myColl.find({type: "photograph"},
1419
{ collation: { locale: "is", caseFirst: "upper" } }
1520
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
/*
2+
Retrieve documents that match "New York" in the "city" field,
3+
sorted by the "name" field by using the German collation.
4+
*/
15
myColl.find({ city: "New York" }, { collation: { locale: "de" } })
26
.sort({ name: 1 });

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
// start findOneAndDelete example without collation
2+
/*
3+
Delete the first document that contains a value greater
4+
than 100 in the "a" field when ordered by using the default
5+
binary collation order.
6+
*/
27
await myColl.findOneAndDelete({ a: { $gt: "100" } });
38
// end findOneAndDelete example without collation
49

510
// start findOneAndDelete example with collation
11+
/*
12+
Delete the first document that contains a value greater
13+
than 100 in the "a" field when ordered by using the
14+
English numeric collation order.
15+
*/
616
myColl.findOneAndDelete(
717
{ a: { $gt: "100" } },
818
{ collation: { locale: "en", numericOrdering: true } },

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
// start findOneAndUpdate without collation
2+
/*
3+
Update the "verified" field to "true" for the first document
4+
that precedes "Gunter" when ordered by using the
5+
default binary collation order.
6+
*/
27
myColl.findOneAndUpdate(
38
{ first_name : { $lt: "Gunter" } },
49
{ $set: { verified: true } }
510
);
611
// end findOneAndUpdate without collation
712

813
// start findOneAndUpdate with collation
14+
/*
15+
Update the "verified" field to "true" for the first document
16+
that precedes "Gunter" when ordered by using the
17+
German phonebook collation order.
18+
*/
919
myColl.findOneAndUpdate(
1020
{ first_name: { $lt: "Gunter" } },
1121
{ $set: { verified: true } },
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
Create an index on the "title" field with the "en_US"
3+
locale collation, specifying ascending ordering of the
4+
"title" field.
5+
*/
16
myColl.createIndex(
27
{ 'title' : 1 },
38
{ 'collation' : { 'locale' : 'en_US' } });
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
// start query index collation
2+
/*
3+
Retrieve documents that match the "year" value "1980"
4+
in descending order of the value of the "title" field,
5+
specifying a collation that uses the index.
6+
*/
27
myColl.find({"year": 1980}, {"collation" : {"locale" : "en_US" }})
38
.sort({"title": -1});
49
// end query index collation
510

611
// start query without index collation
712
// no collation specified
13+
/*
14+
Retrieve documents that match the "year" value "1980"
15+
in descending order of the value of the "title" field
16+
that does not use the collation index.
17+
*/
818
myColl.find({"year": 1980})
919
.sort({"title": -1});
1020

1121
// collation differs from the one on the index
22+
/*
23+
Retrieve documents that match the "year" value "1980"
24+
in descending order of the value of the "title" field,
25+
specifying a collation that does not use the collation
26+
index.
27+
*/
1228
myColl.find({"year": 1980}, {"collation" : {"locale" : "en_US", "strength": 2 }})
1329
.sort({"title": -1});
1430
// end query without index collation

source/fundamentals/collations.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ The following query uses the index we created:
157157
:start-after: start query index collation
158158
:end-before: end query index collation
159159

160-
The following queries **do not** use the index that we created. The first
160+
The following queries **do not** use the index that we created. The first
161161
query does not include a collation and the second contains a different
162162
strength value than the collation on the index.
163163

0 commit comments

Comments
 (0)