|
2 | 2 | movies.create_index("title")
|
3 | 3 | # end-index-single
|
4 | 4 |
|
| 5 | +# start-index-single-collation |
| 6 | +from pymongo.collation import Collation |
| 7 | + |
| 8 | +movies.create_index("title", collation=Collation(locale='fr_CA')) |
| 9 | +# end-index-single-collation |
| 10 | + |
5 | 11 | # start-index-single-query
|
6 | 12 | query = { "title": "Batman" }
|
7 | 13 | sort = [("title", 1)]
|
|
13 | 19 | movies.create_index([("type", pymongo.ASCENDING), ("genre", pymongo.ASCENDING)])
|
14 | 20 | # end-compound-index
|
15 | 21 |
|
| 22 | +# start-compound-index-collation |
| 23 | +from pymongo.collation import Collation |
| 24 | + |
| 25 | +movies.create_index([("type", pymongo.ASCENDING), ("genre", pymongo.ASCENDING)], |
| 26 | + collation=Collation(locale='fr_CA')) |
| 27 | +# end-compound-index-collation |
| 28 | + |
16 | 29 | # start-index-compound-query
|
17 | 30 | query = { "type": "movie", "genre": "Drama" }
|
18 | 31 | sort = [("type", pymongo.ASCENDING), ("genre", pymongo.ASCENDING)]
|
|
24 | 37 | result = movies.create_index("cast")
|
25 | 38 | # end-index-multikey
|
26 | 39 |
|
| 40 | +# start-index-multikey-collation |
| 41 | +from pymongo.collation import Collation |
| 42 | + |
| 43 | +result = movies.create_index("cast", collation=Collation(locale='fr_CA')) |
| 44 | +# end-index-multikey-collation |
| 45 | + |
27 | 46 | # start-index-multikey-query
|
28 | 47 | query = { "cast": "Viola Davis" }
|
29 | 48 |
|
|
36 | 55 | )
|
37 | 56 | # end-index-text-single
|
38 | 57 |
|
| 58 | +# start-index-text-single-collation |
| 59 | +from pymongo.collation import Collation |
| 60 | + |
| 61 | +movies.create_index( |
| 62 | + [( "plot", "text" )], |
| 63 | + collation=Collation(locale='fr_CA') |
| 64 | +) |
| 65 | +# end-index-text-single-collation |
| 66 | + |
39 | 67 | # start-index-text-single-query
|
40 | 68 | query = { "$text": { "$search": "a time-traveling DeLorean" } }
|
41 | 69 |
|
42 | 70 | cursor = movies.find(query)
|
43 | 71 | # end-index-text-single-query
|
44 | 72 |
|
45 | 73 | # start-index-text-multi
|
| 74 | +from pymongo.collation import Collation |
| 75 | + |
46 | 76 | result = myColl.create_index(
|
47 | 77 | [("title", "text"), ("genre", "text")],
|
48 | 78 | default_language="english",
|
49 |
| - weights={ "title": 10, "genre": 3 } |
| 79 | + weights={ "title": 10, "genre": 3 }, |
| 80 | + collation=Collation(locale='fr_CA') |
50 | 81 | )
|
51 | 82 | # end-index-text-multi
|
52 | 83 |
|
|
56 | 87 | )
|
57 | 88 | # end-index-geo
|
58 | 89 |
|
| 90 | +# start-index-geo-collation |
| 91 | +from pymongo.collation import Collation |
| 92 | + |
| 93 | +theaters.create_index( |
| 94 | + [( "location.geo", "2dsphere" )], |
| 95 | + collation=Collation(locale='fr_CA')) |
| 96 | +# end-index-geo-collation |
| 97 | + |
59 | 98 | # start-index-wildcard
|
60 | 99 | movies.create_index({ "location.$**": pymongo.ASCENDING })
|
61 | 100 | # end-index-wildcard
|
62 | 101 |
|
| 102 | +# start-index-wildcard-collation |
| 103 | +movies.create_index({ "location.$**": pymongo.ASCENDING }, |
| 104 | + collation=Collation(locale='fr_CA')) |
| 105 | +# end-index-wildcard-collation |
| 106 | + |
63 | 107 | # start-index-unique
|
64 | 108 | theaters.create_index("theaterId", unique=True)
|
65 | 109 | # end-index-unique
|
66 | 110 |
|
| 111 | +# start-index-unique-collation |
| 112 | +theaters.create_index("theaterId", unique=True, collation=Collation(locale='fr_CA')) |
| 113 | +# end-index-unique-collation |
| 114 | + |
67 | 115 | # start-index-clustered
|
68 | 116 | sample_mflix.create_collection("movies", clusteredIndex={
|
69 | 117 | "key": { "_id": 1 },
|
|
0 commit comments