Skip to content

Instantly share code, notes, and snippets.

@hamiltop
Created May 30, 2012 22:28
Show Gist options
  • Save hamiltop/2839335 to your computer and use it in GitHub Desktop.
Save hamiltop/2839335 to your computer and use it in GitHub Desktop.
It's a mostly empty database with only 4 records being emitted from the view (with reduce=false)
curl -u hamiltop https://hamiltop.cloudant.com/cs360/_design/purchases/_view/most_recent?reduce=false
{"total_rows":4,"offset":0,"rows":[
{"id":"22b7dd2f647009d2161c42bb46d6c5e7","key":["Peter",1338416091.0237810612],"value":10},
{"id":"5c7c2731a493d8cfafd036a7a93415fc","key":["Peter",1338416093.9606831074],"value":30},
{"id":"8d2c99d15c9f37e0af0244c643fe7c84","key":["Peter",1338416096.3526899815],"value":22},
{"id":"22b7dd2f647009d2161c42bb46da3b52","key":["Peter",1338416107.6635489464],"value":19}
]}
When limit=3 is added, only 3 rows are returned.
curl -u hamiltop https://hamiltop.cloudant.com/cs360/_design/purchases/_view/most_recent?reduce=false\&limit=3
{"total_rows":4,"offset":0,"rows":[
{"id":"22b7dd2f647009d2161c42bb46d6c5e7","key":["Peter",1338416091.0237810612],"value":10},
{"id":"5c7c2731a493d8cfafd036a7a93415fc","key":["Peter",1338416093.9606831074],"value":30},
{"id":"8d2c99d15c9f37e0af0244c643fe7c84","key":["Peter",1338416096.3526899815],"value":22}
]}
When reduce is true, the 4 values are summed successfully:
curl -u hamiltop https://hamiltop.cloudant.com/cs360/_design/purchases/_view/most_recent?reduce=true
{"rows":[
{"key":null,"value":81}
]}
When reduce is true and limit = 3, we get the same result.
melker:~ peter$ curl -u hamiltop https://hamiltop.cloudant.com/cs360/_design/purchases/_view/most_recent?reduce=true\&limit=3
{"rows":[
{"key":null,"value":81}
]}
When group_level=2, we get 3 distinct rows:
curl -u hamiltop https://hamiltop.cloudant.com/cs360/_design/purchases/_view/most_recent?reduce=true\&limit=3\&group_level=2
Enter host password for user 'hamiltop':
{"rows":[
{"key":["Peter",1338416091.0237810612],"value":10},
{"key":["Peter",1338416093.9606831074],"value":30},
{"key":["Peter",1338416096.3526899815],"value":22}
]}
When group_level=1, we get 81 rather than 62 like we should:
melker:~ peter$ curl -u hamiltop https://hamiltop.cloudant.com/cs360/_design/purchases/_view/most_recent?reduce=true\&limit=3\&group_level=1
Enter host password for user 'hamiltop':
{"rows":[
{"key":["Peter"],"value":81}
]}
Here are my map and reduce functions:
function (doc){
if(doc.order){
emit([doc.username,doc.timestamp], doc.price)
}
}
function (keys, values, rereduce) {
return sum(values)
}
Anyone know what's up?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment