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.
Answer
Solution:
After a bit of digging through the
QueryBuilder
class, I've foundmapReduceOptions(array)
so added the following to my query after themap
:i.e.
I then wrapped everything in my
map
function withif (counter >= skip && counter < (skip+100))
and I increment
$BatchSkip
in my PHP batch loop.That does the trick. Reference: MongoDB mapReduce options: https://docs.mongodb.com/manual/reference/command/mapReduce/#mapreduce