2012-12-18 21 views
1

我運行的代碼,如:如何準備從MongoDB的外殼相當打印CSV?

db.items.group({ 
    cond: {"id": {$in: [1,2,3]}}, 
    initial: {}, 
    reduce: function(item_data, out) { print(item_data.id + "," + item_data.price); } 
}); 

我想有id,price雙CSV格式輸出(用於特定項目)。然而,沒有什麼被印刷(除的MapReduce的空結果的)。什麼是完成任務的正確方法?

回答

3
db.items.find({ 
    "id": {$in: [1,2,3]} 
}).forEach(function(item_data) { print(item_data.id + "," + item_data.price); })