mongodb mapreduce function does not provide skip functionality, is their any solution to this?

mongodb, nosql

Solution

Ideally a well-structured map-reduce query would allow you to skip particular documents in your collection.

Alternatively, as Sergio points out, you can simply not emit particular documents in map(). Using scope to define a global counter variable is one way to restrict emit to a specified range of documents. As an example, to skip the first 20 docs that are sorted by ObjectID (and thus, sorted by insertion time):

db.collection_name.mapReduce(map, reduce, {out: example_output, sort: {id:-1}, scope: "var counter=0")}; 

Map function:

function(){
    counter ++;
    if (counter > 20){
        emit(key, value);
    }
}

Problem

Mongodb mapreduce function does not provide any way to skip record from database like find function. It has functionality of query, sort & limit options. But I want to skip some records from the database, and I am not getting any way to it. please provide solutions. Thanks in advance.

Original source