Skip to content

Commit

Permalink
Merge pull request #888 from MartinNowak/mongodbCursorSkip
Browse files Browse the repository at this point in the history
add skip method to mongodb cursor
  • Loading branch information
s-ludwig committed Oct 30, 2014
2 parents 9264360 + 9796d65 commit f0510fb
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions source/vibe/db/mongo/cursor.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import vibe.db.mongo.connection;
import vibe.db.mongo.client;

import std.array : array;
import std.algorithm : map, min;
import std.algorithm : map, max, min;
import std.exception;


Expand Down Expand Up @@ -109,7 +109,7 @@ struct MongoCursor(Q = Bson, R = Bson, S = Bson) {
}

/**
Limits the maximum documents that cursor returns.
Limits the number of documents that the cursor returns.
This method must be called before beginnig iteration in order to have
effect. If multiple calls to limit() are made, the one with the lowest
Expand All @@ -129,6 +129,26 @@ struct MongoCursor(Q = Bson, R = Bson, S = Bson) {
return this;
}

/**
Skips a given number of elements at the beginning of the cursor.
This method must be called before beginnig iteration in order to have
effect. If multiple calls to skip() are made, the one with the maximum
number will be chosen.
Params:
count = The number of documents to skip.
Returns: the same cursor
See_Also: $(LINK http://docs.mongodb.org/manual/reference/method/cursor.skip)
*/
MongoCursor skip(int count)
{
m_data.skip(count);
return this;
}

/**
Advances the cursor to the next document of the response.
Expand Down Expand Up @@ -261,6 +281,11 @@ private class MongoCursorData(Q, R, S) {
}
}

void skip(int count) {
// A skip() value of 0 (e.g. “.skip(0)”) is equivalent to setting no skip.
m_nskip = max(m_nskip, count);
}

void popFront()
{
if (!m_iterationStarted) startIterating();
Expand Down

0 comments on commit f0510fb

Please sign in to comment.