Skip to content

Commit a98e077

Browse files
author
Chris Cho
authored
DOCSP-8733: Collation Fundamentals guide (#55)
* DOCSP-8733: Collations Guide
1 parent 905a6bd commit a98e077

9 files changed

+385
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// ignored first line
2+
collection.aggregate(
3+
[
4+
{ $group: { "_id": "$first_name", "nameCount": { "$sum": 1 } } },
5+
{ $sort: { "_id": 1 } },
6+
],
7+
{ collation: { locale: "de@collation=phonebook" } },
8+
);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ignored first line
2+
3+
// start create collection with collation
4+
// Create the collection with a collation
5+
db.createCollection("souvenirs", {
6+
collation: { locale: "fr_CA" },
7+
});
8+
// end create collection with collation
9+
10+
// start collection query without collation
11+
collection.find({type: "photograph"});
12+
// end collection query without collation
13+
14+
// start collection query with collation
15+
collection.find({type: "photograph"},
16+
{ collation: { locale: "is", caseFirst: "upper" } }
17+
);
18+
// end collection query with collation
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// ignored first line
2+
collection.find({ city: "New York" }, { collation: { locale: "de" } })
3+
.sort({ name: 1 });
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ignored first line
2+
// start findOneAndDelete example without collation
3+
await collection.findOneAndDelete({ a: { $gt: "100" } });
4+
// end findOneAndDelete example without collation
5+
6+
// start findOneAndDelete example with collation
7+
collection.findOneAndDelete(
8+
{ a: { $gt: "100" } },
9+
{ collation: { locale: "en", numericOrdering: true } },
10+
);
11+
// end findOneAndDelete example with collation
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// ignored first line
2+
// start findOneAndUpdate without collation
3+
collection.findOneAndUpdate(
4+
{ first_name : { $lt: "Gunter" } },
5+
{ $set: { verified: true } }
6+
);
7+
// end findOneAndUpdate without collation
8+
9+
// start findOneAndUpdate with collation
10+
collection.findOneAndUpdate(
11+
{ first_name: { $lt: "Gunter" } },
12+
{ $set: { verified: true } },
13+
{ collation: { locale: "de@collation=phonebook" } },
14+
);
15+
// end findOneAndUpdate with collation
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// ignored first line
2+
collection.createIndex(
3+
{ 'title' : 1 },
4+
{ 'collation' : { 'locale' : 'en_US' } });
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// ignored first line
2+
// start query index collation
3+
collection.find({"year": 1980}, {"collation" : {"locale" : "en_US" }})
4+
.sort({"title": -1});
5+
// end query index collation
6+
7+
// start query without index collation
8+
// no collation specified
9+
collection.find({"year": 1980})
10+
.sort({"title": -1});
11+
12+
// collation differs from the one on the index
13+
collection.find({"year": 1980}, {"collation" : {"locale" : "en_US", "strength": 2 }})
14+
.sort({"title": -1});
15+
// end query without index collation

source/fundamentals.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Fundamentals
77
.. toctree::
88

99
/fundamentals/connection
10+
/fundamentals/authentication
1011
/fundamentals/crud
1112
/fundamentals/indexes
12-
/fundamentals/authentication
13+
/fundamentals/collations
1314
/fundamentals/logging
1415
/fundamentals/monitoring

0 commit comments

Comments
 (0)