MongoDB map / reduce number

Exiting the map / abbreviation MongoDB includes something like 'counts': {'input': I, 'emit': E, 'output': O}. I thought that I clearly understand what this means until I get into a strange case that I cannot explain.

In my opinion, counts.inputthis is the number of lines that match the condition (as indicated in query). If so, how is it possible that the following two queries have different results?

db.mycollection.find({MY_CONDITION}).count()

db.mycollection.mapReduce(SOME_MAP, SOME_REDUCE, {'query': {MY_CONDITION}}).counts.input

I thought that they should always give the same result, regardless of the map, and reduce functions if the same condition is used.

+3
source share
2 answers

Is your server stable between two calls?

0
source

map/reduce SQL. , . , .

mapReduce() - map/reduce.

. 2 :

{'id':3,'num':5}
{'id':4,'num':5}

function(){
  emit(this.num, 1);
}

2 :

{5, 1}
{5, 1}

:

function(k,vals) {
     var sum=0;
     for(var i in vals) sum += vals[i];
     return sum;
}

1 :

2
+3

Source: https://habr.com/ru/post/1747144/


All Articles