Ho ottenuto un MongoDB piuttosto grande di cui ho bisogno per estrarre statistiche e compro questo acquisto eseguendo una query Riduci mappa.Riduci la mappa MongoDB con la query
Il problema ora è che ho bisogno di restringere la query per utilizzare ad esempio lo stato:. 'Redatto" invece di utilizzare l'intera collezione
Questo è il mio Map/Reduce codice (sto usando Codeigniter): ho cercato di seguire l'ultimo passo in questa interrogazione, ma non riesco a ottenere risultati in modo penso che aggiungo il torto sintassi:. http://cookbook.mongodb.org/patterns/unique_items_map_reduce/
$map = new MongoCode ("function() {
day = Date.UTC(this.created_at.getFullYear(), this.created_at.getMonth(), this.created_at.getDate());
emit ({day: day, _id: this._id}, {created_at: this.created_at, count: 1});
}");
$reduce = new MongoCode ("function(key , values) {
var count = 0;
values.forEach (function(v) {
count += v['count'];
});
return {count: count};
}");
$outer = $this->cimongo->command (array (
"mapreduce" => "documents",
"map" => $map,
"reduce" => $reduce,
"out" => "stats_results"
));
$map = new MongoCode ("function() {
emit(this['_id']['day'], {count: 1});
}");
$reduce = new MongoCode ("function(key , values) {
var count = 0;
values.forEach (function(v) {
count += v['count'];
});
return {count: count};
}");
$outer = $this->cimongo->command (array (
"mapreduce" => "stats_results",
"map" => $map,
"reduce" => $reduce,
"out" => "stats_results_unique"
));
Che cosa si intende con "status uso 'redatto'"? Vuoi evitare di mappare l'intera tabella, o è sufficiente emettendo solo le chiavi con quello stato? Immagino che quello che vuoi sia emettere condizionatamente il risultato in base al campo dello stato. – evnu