[英]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. 由于Doctrine和Mongo
reduce
输出限制,因此我正在处理一个需要使用批查询的集合。 However, I'm stupefied about how to do so. 但是,我对如何做到这一点感到震惊。
Doctrine ODM's MapReduce
doesn't allow the Skip
option. Doctrine ODM的
MapReduce
不允许使用“ Skip
选项。 However, I've found and read about injecting a variable into Scope
(let's say n
), where it can act as a global counter for the MapReduce
, and with an if()
check it can effectively skip emits where the counter is less than n
. 但是,我发现并了解了有关将变量注入到
Scope
(让我们说n
)的知识,在这里它可以充当MapReduce
的全局计数器,并通过if()
检查,它可以有效地跳过计数器小于n
。
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. 但是,这些解释是针对MongoDB的JS实现(猫鼬等)的,而我正在使用Doctrine ODM,因此我不知道该如何做。
Thanks in advance. 提前致谢。
After a bit of digging through the QueryBuilder
class, I've found mapReduceOptions(array)
so added the following to my query after the map
: 经过对
QueryBuilder
类的QueryBuilder
,我发现mapReduceOptions(array)
因此在map
后的查询中添加了以下内容:
->mapReduceOptions(array('scope'=>array('skip'=>$BatchSkip,'counter'=>0)))`
ie 即
->map($map)
->mapReduceOptions(array('scope'=>array('skip'=>$BatchSkip,'counter'=>0)))
->reduce($reduce)
->getQuery()->execute()
I then wrapped everything in my map
function with if (counter >= skip && counter < (skip+100))
然后,我使用
if (counter >= skip && counter < (skip+100))
将所有内容包装在map
函数中
$map = "function(){
if (counter >= skip && counter < (skip+100))
{
.
.
.
emit( key, value );
}";
and I increment $BatchSkip
in my PHP batch loop. 然后在我的PHP批处理循环中增加
$BatchSkip
。
$BatchSkip+=100;
That does the trick. 这样就可以了。 Reference: MongoDB mapReduce options: https://docs.mongodb.com/manual/reference/command/mapReduce/#mapreduce
参考:MongoDB mapReduce选项: https ://docs.mongodb.com/manual/reference/command/mapReduce/#mapreduce
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.