Limit will limit the results to at most n documents. n must be positive. It is an error to specify Limit more than once in a Get query, or at all in a Delete or Update query.
(n int)
| 144 | // It is an error to specify Limit more than once in a Get query, or |
| 145 | // at all in a Delete or Update query. |
| 146 | func (q *Query) Limit(n int) *Query { |
| 147 | if q.err != nil { |
| 148 | return q |
| 149 | } |
| 150 | if n <= 0 { |
| 151 | return q.invalidf("limit value of %d must be greater than zero", n) |
| 152 | } |
| 153 | if q.dq.Limit > 0 { |
| 154 | return q.invalidf("query can have at most one limit clause") |
| 155 | } |
| 156 | q.dq.Limit = n |
| 157 | return q |
| 158 | } |
| 159 | |
| 160 | // Ascending and Descending are constants for use in the OrderBy method. |
| 161 | const ( |