Skip to content

Commit a522af2

Browse files
committed
Allow partial results flag to be set
1 parent eeefdec commit a522af2

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

session.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,7 +2912,6 @@ func (p *Pipe) SetMaxTime(d time.Duration) *Pipe {
29122912
return p
29132913
}
29142914

2915-
29162915
// Collation allows to specify language-specific rules for string comparison,
29172916
// such as rules for lettercase and accent marks.
29182917
// When specifying collation, the locale field is mandatory; all other collation
@@ -3577,6 +3576,13 @@ func (q *Query) SetMaxTime(d time.Duration) *Query {
35773576
return q
35783577
}
35793578

3579+
func (q *Query) AllowPartial() *Query {
3580+
q.m.Lock()
3581+
q.op.AllowPartial()
3582+
q.m.Unlock()
3583+
return q
3584+
}
3585+
35803586
// Snapshot will force the performed query to make use of an available
35813587
// index on the _id field to prevent the same document from being returned
35823588
// more than once in a single iteration. This might happen without this
@@ -3753,23 +3759,24 @@ func prepareFindOp(socket *mongoSocket, op *queryOp, limit int32) bool {
37533759
}
37543760

37553761
find := findCmd{
3756-
Collection: op.collection[nameDot+1:],
3757-
Filter: op.query,
3758-
Projection: op.selector,
3759-
Sort: op.options.OrderBy,
3760-
Skip: op.skip,
3761-
Limit: limit,
3762-
MaxTimeMS: op.options.MaxTimeMS,
3763-
MaxScan: op.options.MaxScan,
3764-
Hint: op.options.Hint,
3765-
Comment: op.options.Comment,
3766-
Snapshot: op.options.Snapshot,
3767-
Collation: op.options.Collation,
3768-
Tailable: op.flags&flagTailable != 0,
3769-
AwaitData: op.flags&flagAwaitData != 0,
3770-
OplogReplay: op.flags&flagLogReplay != 0,
3771-
NoCursorTimeout: op.flags&flagNoCursorTimeout != 0,
3772-
ReadConcern: readLevel{level: op.readConcern},
3762+
Collection: op.collection[nameDot+1:],
3763+
Filter: op.query,
3764+
Projection: op.selector,
3765+
Sort: op.options.OrderBy,
3766+
Skip: op.skip,
3767+
Limit: limit,
3768+
MaxTimeMS: op.options.MaxTimeMS,
3769+
MaxScan: op.options.MaxScan,
3770+
Hint: op.options.Hint,
3771+
Comment: op.options.Comment,
3772+
Snapshot: op.options.Snapshot,
3773+
Collation: op.options.Collation,
3774+
Tailable: op.flags&flagTailable != 0,
3775+
AwaitData: op.flags&flagAwaitData != 0,
3776+
OplogReplay: op.flags&flagLogReplay != 0,
3777+
NoCursorTimeout: op.flags&flagNoCursorTimeout != 0,
3778+
ReadConcern: readLevel{level: op.readConcern},
3779+
AllowPartialResults: op.flags&flagPartial != 0,
37733780
}
37743781

37753782
if op.limit < 0 {

socket.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ const (
6868
flagLogReplay
6969
flagNoCursorTimeout
7070
flagAwaitData
71+
flagExhaust
72+
flagPartial
7173
)
7274

7375
type queryOp struct {
@@ -98,6 +100,10 @@ type queryWrapper struct {
98100
Collation *Collation `bson:"$collation,omitempty"`
99101
}
100102

103+
func (op *queryOp) AllowPartial() {
104+
op.flags |= flagPartial
105+
}
106+
101107
func (op *queryOp) finalQuery(socket *mongoSocket) interface{} {
102108
if op.flags&flagSlaveOk != 0 && socket.ServerInfo().Mongos {
103109
var modeName string

0 commit comments

Comments
 (0)