summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_limit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/document_source_limit.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_limit.cpp66
1 files changed, 31 insertions, 35 deletions
diff --git a/src/mongo/db/pipeline/document_source_limit.cpp b/src/mongo/db/pipeline/document_source_limit.cpp
index 863bc5f16a7..981b930fddc 100644
--- a/src/mongo/db/pipeline/document_source_limit.cpp
+++ b/src/mongo/db/pipeline/document_source_limit.cpp
@@ -12,31 +12,39 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* As a special exception, the copyright holders give permission to link the
+* code of portions of this program with the OpenSSL library under certain
+* conditions as described in each individual source file and distribute
+* linked combinations including the program with the OpenSSL library. You
+* must comply with the GNU Affero General Public License in all respects for
+* all of the code used other than as permitted herein. If you modify file(s)
+* with this exception, you may extend this exception to your version of the
+* file(s), but you are not obligated to do so. If you do not wish to do so,
+* delete this exception statement from your version. If you delete this
+* exception statement from all source files in the program, then also delete
+* it in the license file.
*/
-#include "pch.h"
-
-#include "db/pipeline/document_source.h"
+#include "mongo/pch.h"
-#include "db/jsobj.h"
-#include "db/pipeline/document.h"
-#include "db/pipeline/expression.h"
-#include "db/pipeline/expression_context.h"
-#include "db/pipeline/value.h"
+#include "mongo/db/jsobj.h"
+#include "mongo/db/pipeline/document.h"
+#include "mongo/db/pipeline/document_source.h"
+#include "mongo/db/pipeline/expression.h"
+#include "mongo/db/pipeline/expression_context.h"
+#include "mongo/db/pipeline/value.h"
namespace mongo {
const char DocumentSourceLimit::limitName[] = "$limit";
DocumentSourceLimit::DocumentSourceLimit(const intrusive_ptr<ExpressionContext> &pExpCtx,
long long limit)
- : SplittableDocumentSource(pExpCtx)
+ : DocumentSource(pExpCtx)
, limit(limit)
, count(0)
{}
- DocumentSourceLimit::~DocumentSourceLimit() {
- }
-
const char *DocumentSourceLimit::getSourceName() const {
return limitName;
}
@@ -56,31 +64,19 @@ namespace mongo {
return true;
}
- bool DocumentSourceLimit::eof() {
- return pSource->eof() || count >= limit;
- }
+ boost::optional<Document> DocumentSourceLimit::getNext() {
+ pExpCtx->checkForInterrupt();
- bool DocumentSourceLimit::advance() {
- DocumentSource::advance(); // check for interrupts
-
- ++count;
- if (count >= limit) {
- // This is required for the DocumentSourceCursor to release its read lock, see
- // SERVER-6123.
+ if (++count > limit) {
pSource->dispose();
-
- return false;
+ return boost::none;
}
- return pSource->advance();
- }
- Document DocumentSourceLimit::getCurrent() {
- return pSource->getCurrent();
+ return pSource->getNext();
}
- void DocumentSourceLimit::sourceToBson(
- BSONObjBuilder *pBuilder, bool explain) const {
- pBuilder->append("$limit", limit);
+ Value DocumentSourceLimit::serialize(bool explain) const {
+ return Value(DOC(getSourceName() << limit));
}
intrusive_ptr<DocumentSourceLimit> DocumentSourceLimit::create(
@@ -92,12 +88,12 @@ namespace mongo {
}
intrusive_ptr<DocumentSource> DocumentSourceLimit::createFromBson(
- BSONElement *pBsonElement,
- const intrusive_ptr<ExpressionContext> &pExpCtx) {
+ BSONElement elem,
+ const intrusive_ptr<ExpressionContext> &pExpCtx) {
uassert(15957, "the limit must be specified as a number",
- pBsonElement->isNumber());
+ elem.isNumber());
- long long limit = pBsonElement->numberLong();
+ long long limit = elem.numberLong();
return DocumentSourceLimit::create(pExpCtx, limit);
}
}