Alexandr T
Alexandr T

Reputation: 1501

Ruby: connect to Couchbase

I want to connect to Couchbase DB server trough couchbase gem.

require 'couchbase'
c = Couchbase.connect('http://<server>:<port>/pools/default/buckets/auth')

I get an error:

*** Couchbase::Error::BucketNotFound Exception: bootstrap error, The bucket requested does not exist

The following code works with the (couchbase python package):

from couchbase.bucket import Bucket
c = Bucket('couchbase://<server>/auth')

How I can connect from ruby by using connection string couchbase://<server>/auth?

Upvotes: 1

Views: 307

Answers (2)

Alexandr T
Alexandr T

Reputation: 1501

Need specify bucket if it is custom:

Couchbase.connect("http://<server>:8091/pools/default", :bucket => 'auth')

Upvotes: 0

beamatronic
beamatronic

Reputation: 89

Here is what I see on my machine.

# ruby --version
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]

# gem --version
1.3.7

# gem list --local

*** LOCAL GEMS ***

connection_pool (2.2.0)
couchbase (1.3.14)
multi_json (1.12.1)
yaji (0.3.5)

# cat test.ruby
require 'couchbase'
c = Couchbase.connect('http://localhost:8091/pools/default/buckets/BUCKETNAME')
puts c.get('test123')


# cbc get test123 -U couchbase://localhost/BUCKETNAME 
test123              CAS=0x8f1269ea6014, Flags=0x0. Size=17
{"hello":"there"}

# ruby -rubygems test.ruby
[WARNING] MultiJson is using the default adapter (ok_json). We recommend loading a different JSON library to improve performance.
hellothere

This was on one of my Couchbase nodes. I have bucket called BUCKETNAME and it contains a document with key "test123" and the content of the document is

{
  "hello": "there"
}

Upvotes: 2

Related Questions