php - Doctrine ODM (MongoDB) MapReduce + Skip


I'm working on with a set where I need to use batch-querying due to Doctrine's - and Mongo's -reduce output limitations. However, I'm stupefied about how to do so.

Doctrine ODM'sMapReduce doesn't allow theSkip option. However, I've found and read about injecting a variable intoScope (let's sayn), where it can act as a global counter for theMapReduce, and with anif() check it can effectively skip emits where the counter is less thann.

However, those explanations were for MongoDB's JS implementations (mongoose etc.), whereas I'm working with Doctrine ODM, so I've no idea how to go about this.

Thanks in advance.




After a bit of digging through theQueryBuilder class, I've foundmapReduceOptions(array) so added the following to my query after themap:




I then wrapped everything in mymap function withif (counter >= skip && counter < (skip+100))

$map = "function(){
  if (counter >= skip && counter < (skip+100))
    emit( key, value ); 

and I increment$BatchSkip in my PHP batch loop.


That does the trick. Reference: MongoDB mapReduce options:

People are also looking for solutions to the problem: php - how works or operator in if statements and print


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.