Пример #1
0
def map_reduce():
	conn = Connection('localhost')['int_test']['track_log']
	
	"""docstring for map_reduce"""
	map = Code("function (){"
				"emit(this.device_no, 1);"
	"}")
	
	reduce = Code("function (key, values) {"
		"var x = 0;"
		"values.forEach( function(v) {x += v});"
		"return x;"
	"}")
	
	result = conn.map_reduce(map, reduce, "map_results")
	for doc in result.find():
		print doc
Пример #2
0
                for (var i = 1; i < values.length; i++) {
                    if (values[i] > result) {
                        result = values[i];
                    }
                }
                break;
            case 'min':
                result = values[0];
                for (var i = 1; i < values.length; i++) {
                    if (values[i] < result) {
                        result = values[i];
                    }
                }
                break;
            case 'total':
            case 'count':
            default:
                for (var i = 0; i < values.length; i++) {
                    result += values[i];
                }
                break;
        }
        
        return result;
    }
""")

ttt = Connection().parang.tictactoe
for row in ttt.map_reduce(total_map, total_reduce).find():
    print "%(_id)s:\t%(value)s" % row