1
프로젝트에 mapReduce
을 사용해야하고 documentation을 따라하기 시작했습니다.Map MongoDB에서 Reduce : undefined가 함수가 아닙니다.
페이지에서 first 예를 따라 test project을 생성했습니다.
나는 몽고에서 test
라는 이름의 데이터베이스를 만든, 내가 수집 col_one
예에서 개체를 삽입 :
{
_id: ObjectId("50a8240b927d5d8b5891743c"),
cust_id: "abc123",
ord_date: new Date("Oct 04, 2012"),
status: 'A',
price: 250,
items: [ { sku: "mmm", qty: 5, price: 2.5 },
{ sku: "nnn", qty: 5, price: 2.5 } ]
}
내 코드 (예처럼) 간단하다 :
// MongoDB part
// Create server
var mapFunction1 = function() {
emit(this.cust_id, this.price);
};
var reduceFunction1 = function(keyCustId, valuesPrices) {
return Array.sum(valuesPrices);
};
collection.mapReduce(
mapFunction1,
reduceFunction1,
{ out: "col_two" }
);
// Print items from col_two
이 오류가 발생합니다 :
.../node_modules/mongodb/lib/mongodb/connection/server.js:524
throw err;
^TypeError: undefined is not a function
이 경우, 이 오류가 사라집니다.
collection.mapReduce(
mapFunction1,
reduceFunction1,
{ out: "col_two" },
function() {
// Print items from col_two
}
);
오류가 사라지는 이유는 무엇입니까?
콜백은'mapReduce'의 필수 매개 변수이기 때문에. [docs] (http://mongodb.github.com/node-mongodb-native/api-generated/collection.html#mapreduce)를 참조하십시오. – JohnnyHK
@ JohnnyHK, 왜 그들은 [여기] (http://docs.mongodb.org/manual/applications/map-reduce/#return-the-total-price-per-customer-id) 콜백을 사용하지 않았습니까? –
이 예제는 동기 인터페이스 인 쉘을 사용하기 때문에. – JohnnyHK