diff --git a/session.go b/session.go index 5801e225c..5ceeb78d3 100644 --- a/session.go +++ b/session.go @@ -2973,6 +2973,13 @@ func (q *Query) SetMaxTime(d time.Duration) *Query { return q } +func (q *Query) AllowPartial() *Query { + q.m.Lock() + q.op.AllowPartial() + q.m.Unlock() + return q +} + // Snapshot will force the performed query to make use of an available // index on the _id field to prevent the same document from being returned // more than once in a single iteration. This might happen without this @@ -3149,18 +3156,19 @@ func prepareFindOp(socket *mongoSocket, op *queryOp, limit int32) bool { } find := findCmd{ - Collection: op.collection[nameDot+1:], - Filter: op.query, - Projection: op.selector, - Sort: op.options.OrderBy, - Skip: op.skip, - Limit: limit, - MaxTimeMS: op.options.MaxTimeMS, - MaxScan: op.options.MaxScan, - Hint: op.options.Hint, - Comment: op.options.Comment, - Snapshot: op.options.Snapshot, - OplogReplay: op.flags&flagLogReplay != 0, + Collection: op.collection[nameDot+1:], + Filter: op.query, + Projection: op.selector, + Sort: op.options.OrderBy, + Skip: op.skip, + Limit: limit, + MaxTimeMS: op.options.MaxTimeMS, + MaxScan: op.options.MaxScan, + Hint: op.options.Hint, + Comment: op.options.Comment, + Snapshot: op.options.Snapshot, + OplogReplay: op.flags&flagLogReplay != 0, + AllowPartialResults: op.flags&flagPartial != 0, } if op.limit < 0 { find.BatchSize = -op.limit diff --git a/socket.go b/socket.go index a2343354d..00dfbb497 100644 --- a/socket.go +++ b/socket.go @@ -64,6 +64,8 @@ const ( flagLogReplay flagNoCursorTimeout flagAwaitData + flagExhaust + flagPartial ) type queryOp struct { @@ -93,6 +95,10 @@ type queryWrapper struct { Comment string "$comment,omitempty" } +func (op *queryOp) AllowPartial() { + op.flags |= flagPartial +} + func (op *queryOp) finalQuery(socket *mongoSocket) interface{} { if op.flags&flagSlaveOk != 0 && socket.ServerInfo().Mongos { var modeName string