MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

PHP MongoDB map reduce: db assertion failure

In mapReduce, il valore restituito da reduce deve avere la stessa forma dei valori passati a reduce e di ciò che emette map.

Esempio minimale:

$map = new MongoCode("function() { emit(this.topic_id, { last_post: this.date_posted }); }");

$reduce = new MongoCode("function(key, values) {
  var max = ISODate('1970-01-01T00:00:00Z');
  values.forEach(function(val) {
    if (max < val.last_post) max = val.last_post;
  });
  return { last_post: max };
}");

La forma emessa, passata e restituita deve restare coerente per evitare assertion failure.