对 Map Function 进行故障排除
{
_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 } ]
}var map = function() { emit(this.cust_id, this.price); };var emit = function(key, value) { print("emit"); print("key: " + key + " value: " + tojson(value)); }var myDoc = db.orders.findOne( { _id: ObjectId("50a8240b927d5d8b5891743c") } ); map.apply(myDoc);emit key: abc123 value:250var myCursor = db.orders.find( { cust_id: "abc123" } ); while (myCursor.hasNext()) { var doc = myCursor.next(); print ("document _id= " + tojson(doc._id)); map.apply(doc); print(); }
最后更新于