Bitte beachten Sie bitte den Mongo Mantel:Was ist los mit dieser Map-Reduce-Abfrage auf Mongo?
> map
function map() {
if (this.server_location[0] == -77.0367) {
emit(this._id, this);
}
}
> reduce
function reduce(key, values) {
return values[0];
}
> db.static.mapReduce(map, reduce, {out: 'x', query: {client_location:{$near:[-75.5,41.89], $maxDistance: 1}}})
{
"result" : "x",
"timeMillis" : 43,
"counts" : {
"input" : 100,
"emit" : 0,
"reduce" : 0,
"output" : 0
},
"ok" : 1,
}
> db.static.find({client_location:{$near:[-75.5,41.89], $maxDistance: 1}, $where: "this.server_location[0] == -77.0367" }).count()
7
>
ich zum ersten Mal eine Karte-Implementierung reduzieren leite und dann die gleiche Sache wie eine Abfrage. Die Ergebnisse sind unterschiedlich. Was mache ich falsch?
EDIT
Ich habe die Karte Funktion wie folgt geändert:
function map()
{
if (this.server_location[0] < -77 && this.server_location[0] > -78)
{
print(this._id + ": server_location[0] = " + this.server_location[0]);
}
if (this.server_location[0] == -77.0367)
{
emit(this._id, this);
}
}
Ausführen der Karten reduzieren druckt die folgenden auf der mongod Konsole:
1412262185: server_location[0] = -77.8586
1412493418: server_location[0] = -77.8586
1412497409: server_location[0] = -77.8586
1412559515: server_location[0] = -77.8586
1412666474: server_location[0] = -77.6114
1412895269: server_location[0] = -77.6114
1412962473: server_location[0] = -77.6114
Auf der anderen Hand, die Abfrage mit der $where
Anweisung ergibt die folgenden Ergebnisse:
/* 0 */
{
"_id" : 1411941588,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.6485, 41.4201]
}
/* 1 */
{
"_id" : 1412382406,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.728, 41.4486]
}
/* 2 */
{
"_id" : 1412987742,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.8962, 41.2808]
}
/* 3 */
{
"_id" : 1412988363,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.8962, 41.2808]
}
/* 4 */
{
"_id" : 1412989085,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.8962, 41.2808]
}
/* 5 */
{
"_id" : 1413017856,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-75.9534, 41.2973]
}
/* 6 */
{
"_id" : 1412398078,
"server_location" : [-77.0367, 38.8951],
"client_location" : [-76.0341, 41.1838]
}
Ich verstehe nicht, wie kommen diese während der Karte-reduzieren nicht gefunden wurden. Jemand?
EDIT 2
BTW, wenn ich den Zustand der $where
Klausel this.server_location[0] == -77.8586 || this.server_location[0] == -77.6114
ich durch die Kartenfunktion zurück 50 Ergebnisse und nicht 7 als gedruckte ändern. Es ist merkwürdig, dass die 7 Ergebnisse, die durch die Map-Reduction gedruckt wurden, die ersten 7 Ergebnisse von den 50 sind, die durch die Abfrage gefunden wurden.
Ich bin verloren.
EDIT 3
Ich glaube, ich weiß, was das Problem ist. Scheint so, als würde map-reduce nur mit den ersten 100 Datensätzen gefüttert werden. Die Frage ist was als nächstes?
Entschuldigung für die Dummy-Antwort. Ich werde Mongo laden und es versuchen. – brice
Bitte, tun Sie. Vielen Dank. – mark
Was ist, wenn Sie Maxdistance von 3 versucht? Findet es das Zeug? – Sammaye