javascript - How to get a "fieldcount" (like wordcount) on CouchDB/Cloudant? -


trying count of fields, classic word count example. thought trivial...

enter image description here

but got useless result...

{"rows":[ {"key":null,"value":212785214} ]} 

how can wanted... inventory of fields used in documents, count of how many times occur?

to count of each key in document, create "map" function this:

function (doc) {   var keys = object.keys(doc);   for(var in keys) {     emit(keys[i], null);   } } 

and use built in _count reducer.

you can retrieve grouped answer accessing view so:

/mydb/_design/<designdocname>/_view/<viewname>?group_level=1 

which produce grouped keys , counts this:

{"rows":[ {"key":"_id","value":4}, {"key":"_rev","value":4}, {"key":"a","value":3}, {"key":"c","value":1} ]} 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -