Skip to content

DOCSP-32718: add CodeWhisperer comments to collation code snippets #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/code-snippets/collation/aggregation-collation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Retrieve the total matching names, grouped by the first_name field and sorted by using the German phonebook collation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: since this comment is causing horizontal scroll, make it a multi line comment. Or, could it be more beneficial to comment before the each stage + the collation line?

myColl.aggregate(
[
{ $group: { "_id": "$first_name", "nameCount": { "$sum": 1 } } },
Expand Down
7 changes: 6 additions & 1 deletion source/code-snippets/collation/collection-collation.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// start create collection with collation
// Create the collection with a collation
// Create the "souvenirs" collection and specify the French Canadian collation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: no periods for single line comments

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applies throughout

db.createCollection("souvenirs", {
collation: { locale: "fr_CA" },
});
// end create collection with collation

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

// start collection query with collation
/*
Retrieve documents that match "photograph" in the "type" field,
sorted by the Iceland collation and uppercase precedence.
*/
myColl.find({type: "photograph"},
{ collation: { locale: "is", caseFirst: "upper" } }
);
Expand Down
4 changes: 4 additions & 0 deletions source/code-snippets/collation/find-sort-collation.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/*
Retrieve documents that match "New York" in the "city" field,
sorted by the "name" field by using the German collation.
*/
myColl.find({ city: "New York" }, { collation: { locale: "de" } })
.sort({ name: 1 });
10 changes: 10 additions & 0 deletions source/code-snippets/collation/findOneAndDelete-collation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// start findOneAndDelete example without collation
/*
Delete the first document that contains a value greater
than 100 in the "a" field when ordered by using the default
binary collation order.
*/
await myColl.findOneAndDelete({ a: { $gt: "100" } });
// end findOneAndDelete example without collation

// start findOneAndDelete example with collation
/*
Delete the first document that contains a value greater
than 100 in the "a" field when ordered by using the
English numeric collation order.
*/
myColl.findOneAndDelete(
{ a: { $gt: "100" } },
{ collation: { locale: "en", numericOrdering: true } },
Expand Down
10 changes: 10 additions & 0 deletions source/code-snippets/collation/findOneAndUpdate-collation.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// start findOneAndUpdate without collation
/*
Update the "verified" field to "true" for the first document
that precedes "Gunter" when ordered by using the
default binary collation order.
*/
myColl.findOneAndUpdate(
{ first_name : { $lt: "Gunter" } },
{ $set: { verified: true } }
);
// end findOneAndUpdate without collation

// start findOneAndUpdate with collation
/*
Update the "verified" field to "true" for the first document
that precedes "Gunter" when ordered by using the
German phonebook collation order.
*/
myColl.findOneAndUpdate(
{ first_name: { $lt: "Gunter" } },
{ $set: { verified: true } },
Expand Down
5 changes: 5 additions & 0 deletions source/code-snippets/collation/index-collation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
Create an index on the "title" field with the "en_US"
locale collation, specifying ascending ordering of the
"title" field.
*/
myColl.createIndex(
{ 'title' : 1 },
{ 'collation' : { 'locale' : 'en_US' } });
16 changes: 16 additions & 0 deletions source/code-snippets/collation/query-index-collation.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
// start query index collation
/*
Retrieve documents that match the "year" value "1980"
in descending order of the value of the "title" field,
specifying a collation that uses the index.
*/
myColl.find({"year": 1980}, {"collation" : {"locale" : "en_US" }})
.sort({"title": -1});
// end query index collation

// start query without index collation
// no collation specified
/*
Retrieve documents that match the "year" value "1980"
in descending order of the value of the "title" field
that does not use the collation index.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: For this code comment and the next, is there a way to combine the code comments content so these aren't stacked?

myColl.find({"year": 1980})
.sort({"title": -1});

// collation differs from the one on the index
/*
Retrieve documents that match the "year" value "1980"
in descending order of the value of the "title" field,
specifying a collation that does not use the collation
index.
*/
myColl.find({"year": 1980}, {"collation" : {"locale" : "en_US", "strength": 2 }})
.sort({"title": -1});
// end query without index collation
2 changes: 1 addition & 1 deletion source/fundamentals/collations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ The following query uses the index we created:
:start-after: start query index collation
:end-before: end query index collation

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

Expand Down