File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change 13
13
14
14
package qmgo
15
15
16
+ import "go.mongodb.org/mongo-driver/mongo/options"
17
+
16
18
// CollectionI
17
19
// 集合操作接口
18
20
//type CollectionI interface {
@@ -48,6 +50,7 @@ type CursorI interface {
48
50
49
51
// QueryI Query interface
50
52
type QueryI interface {
53
+ Collation (collation * options.Collation ) QueryI
51
54
Sort (fields ... string ) QueryI
52
55
Select (selector interface {}) QueryI
53
56
Skip (n int64 ) QueryI
Original file line number Diff line number Diff line change @@ -37,13 +37,20 @@ type Query struct {
37
37
skip * int64
38
38
batchSize * int64
39
39
noCursorTimeout * bool
40
+ collation * options.Collation
40
41
41
42
ctx context.Context
42
43
collection * mongo.Collection
43
44
opts []qOpts.FindOptions
44
45
registry * bsoncodec.Registry
45
46
}
46
47
48
+ func (q * Query ) Collation (collation * options.Collation ) QueryI {
49
+ newQ := q
50
+ newQ .collation = collation
51
+ return newQ
52
+ }
53
+
47
54
func (q * Query ) NoCursorTimeout (n bool ) QueryI {
48
55
newQ := q
49
56
newQ .noCursorTimeout = & n
@@ -128,6 +135,9 @@ func (q *Query) One(result interface{}) error {
128
135
}
129
136
opt := options .FindOne ()
130
137
138
+ if q .collation != nil {
139
+ opt .SetCollation (q .collation )
140
+ }
131
141
if q .sort != nil {
132
142
opt .SetSort (q .sort )
133
143
}
@@ -163,6 +173,9 @@ func (q *Query) All(result interface{}) error {
163
173
}
164
174
}
165
175
opt := options .Find ()
176
+ if q .collation != nil {
177
+ opt .SetCollation (q .collation )
178
+ }
166
179
if q .sort != nil {
167
180
opt .SetSort (q .sort )
168
181
}
You can’t perform that action at this time.
0 commit comments