You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having problems with the Views example on the README page. When I do:
res.each do |row|
# Returns extended results by default
puts "#{row.key}: #{row.value}"
end
The output I get is:
hello-world: {:title=>"Hello World", :body=>"Well hello and welcome to my new blog...", :date=>"2009/01/15 15:52:20"}
biking: {:title=>"Biking", :body=>"My biggest hobby is mountainbiking. The other day...", :date=>"2009/01/30 18:04:11"}
bought-a-cat: {:title=>"Bought a Cat", :body=>"I went to the the pet store.", :date=>"2009/01/30 20:04:11"}
I think map() should emit the date as row.key and the title as row.value.
Full code, which is copied from the README:
require 'libcouchbase'
bucket = Libcouchbase::Bucket.new(
hosts: '127.0.0.1',
bucket: 'recent-posts',
username: '7stud',
password: 'abc123')
bucket['biking'] = {:title => 'Biking',
:body => 'My biggest hobby is mountainbiking. The other day...',
:date => '2009/01/30 18:04:11'}
bucket['bought-a-cat'] = {:title => 'Bought a Cat',
:body => 'I went to the the pet store.',
:date => '2009/01/30 20:04:11'}
bucket['hello-world'] = {:title => 'Hello World',
:body => 'Well hello and welcome to my new blog...',
:date => '2009/01/15 15:52:20'}
view_doc = %q|
{
"_id": "_design/blog",
"language": "javascript",
"views": {
"recent_posts": {
"map": "function(doc){if(doc.date && doc.title){emit(doc.date, doc.title);}}"
}
}
}
|
bucket.save_design_doc(view_doc)
blog = bucket.design_docs['blog']
p blog.views
res = blog.view('recent_posts') #=> #<Libcouchbase::Results:0x007fbaed12c988>
res.each do |row|
# Returns extended results by default
puts "#{row.key}: #{row.value}"
end
I'm not sure what the comment #Returns extended results by default means. If I do:
res = blog.view('recent_posts', include_docs: false)
then my results are:
hello-world:
biking:
bought-a-cat:
It doesn't seem to matter what the map function emit()'s because the results are always the same. For instance, I get the same output with emit(1, 2), emit('abc', '123'), and emit(doc.date, doc.title)
The text was updated successfully, but these errors were encountered:
7stud
changed the title
Problem with Views(Map/Reduce) example
Problem with the Views(Map/Reduce) example
Feb 4, 2018
Couchbase:
Community Edition 5.0.1 build 5003
I'm having problems with the
Views
example on the README page. When I do:The output I get is:
I expected the output:
Because the map function is this:
I think
map()
should emit the date asrow.key
and the title asrow.value
.Full code, which is copied from the README:
I'm not sure what the comment
#Returns extended results by default
means. If I do:then my results are:
It doesn't seem to matter what the map function emit()'s because the results are always the same. For instance, I get the same output with
emit(1, 2)
,emit('abc', '123')
, andemit(doc.date, doc.title)
The text was updated successfully, but these errors were encountered: