This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> Article.enumerate_all_tags | |
=> {"security"=>2, "ldap"=>1, "xen"=>1, "stories"=>3, "rails"=>13, "xeriom"=>3, "mysql"=>3, ... } | |
>> Article.find_all_tags | |
=> ["agile", "ajax", "apache", "api", "caching", "coding", ... ] | |
>> Article.find_all_author_ids | |
=> ["[email protected]"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id": "_design/articles", | |
"_rev": "3752119467", | |
"language": "javascript", | |
"views": { | |
"by_author_id_and_status_and_posted_at": { | |
"map": "function(doc) { if(doc.type == 'article') { emit([doc.author_id, doc.status, doc.posted_at], doc); } }" | |
} | |
// other view omitted for brevity | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Article.find(:all, :conditions => { :author_id => "[email protected]", :status => "Live" }, :order => :posted_at) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id": "_design/articles", | |
"_rev": "1532981864", | |
"language": "javascript", | |
"views": { | |
"by_author_id_and_status": { | |
"map": "function(doc) { if(doc.type == 'article') { emit([doc.author_id, doc.status], doc); } }" | |
} | |
// other views cut for brevity | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Article.find(:all, :conditions => { :author_id => "[email protected]", :status => "Live" }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GET http://localhost:5984/blog/_view/articles/tags?group=true&group_level=1 | |
{"rows":[ | |
{"key":"awesome","value":1}, | |
{"key":"agile","value":2}, | |
{"key":"ajax","value":2}, | |
{"key":"apache","value":2}, | |
{"key":"api","value":1}, | |
{"key":"caching","value":1}, | |
{"key":"coding","value":7}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"tags": { | |
"map": "function(doc) { if(doc.type == 'article') { for(var i in doc.tags) { emit(doc.tags[i], 1); }}}", | |
"reduce": "function(tag, counts) { var sum = 0; for(var i = 0; i < counts.length; i++) { sum += counts[i]; }; return sum; }" | |
} | |
// other views omitted for brevity | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(tag, counts) { | |
var sum = 0; | |
for(var i=0; i < counts.length; i++) { | |
sum += counts[i]; | |
} | |
return sum; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(doc) { | |
if(doc.type == 'article') { | |
for(i in doc.tags) { | |
emit(doc.tags[i], 1); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id": "monkeys-are-awesome", | |
"_rev": "1534115156", | |
"type": "article", | |
"title": "Monkeys are awesome", | |
"posted_at": "2008-09-14T20:45:14Z", | |
"tags": [ | |
"monkeys", | |
"awesome" | |
], |