Sha256: ea5a68867ffa1ce7cc9f66fdb777dd8740ff90630f3def62cdf683e2c29e7fa4

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

require 'couchbase'
include Couchbase

options = Cluster::ClusterOptions.new
options.authenticate("Administrator", "password")
cluster = Cluster.connect("couchbase://localhost", options)
bucket = cluster.bucket("default")
collection = bucket.default_collection

document = {
    name: "Douglas Reynholm",
    email: "douglas@reynholmindustries.com",
    addresses: {
        billing: {
            line1: "123 Any Street",
            line2: "Anytown",
            country: "United Kingdom"
        },
        delivery: {
            line1: "123 Any Street",
            line2: "Anytown",
            country: "United Kingdom"
        }
    },
    purchases: {
        complete: [339, 976, 442, 666],
        abandoned: [157, 42, 999]
    }
}
collection.upsert("customer123", document)

res = collection.mutate_in("customer123", [
    MutateInSpec.upsert("fax", "311-555-0151")
])
puts "The document has been modified successfully: cas=#{res.cas}"

res = collection.mutate_in("customer123", [
    MutateInSpec.upsert("_framework.model_type", "Customer").xattr,
    MutateInSpec.remove("addresses.billing[2]"),
    MutateInSpec.replace("email", "dougr96@hotmail.com"),
])
puts "The document has been modified successfully: cas=#{res.cas}"

res = collection.lookup_in "customer123", [
    LookupInSpec.get("addresses.delivery.country"),
    LookupInSpec.exists("purchases.pending[-1]"),
]
puts "The customer's delivery country is #{res.content(0)}"
if res.exists?(1)
  puts "The customer has pending purchases"
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
couchbase-3.0.0.beta.1-universal-darwin-19 examples/subdocument.rb
couchbase-3.0.0.beta.1 examples/subdocument.rb
couchbase-3.0.0.alpha.5-x86_64-linux examples/subdocument.rb
couchbase-3.0.0.alpha.5-universal-darwin-19 examples/subdocument.rb
couchbase-3.0.0.alpha.5-x86_64-darwin-19 examples/subdocument.rb
couchbase-3.0.0.alpha.5 examples/subdocument.rb