couchbaselabs / devguide-examples Goto Github PK
View Code? Open in Web Editor NEWExamples for topics in the developer guide
License: Apache License 2.0
Examples for topics in the developer guide
License: Apache License 2.0
I have couchbase running on docker and i can access it via localhost in browser but when i run this script i get
ERRROR CREATING DOCUMENT: The operation has timed out.
ERRROR RETURNING DOCUMENT: The operation has timed out.
package main
import (
"fmt"
"gopkg.in/couchbaselabs/gocb.v1"
)
// bucket reference - reuse as bucket reference in the application
var bucket *gocb.Bucket
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://localhost")
if err != nil {
fmt.Println("ERRROR CONNECTING TO CLUSTER:", err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("travel-sample", "")
if err != nil {
fmt.Println("ERRROR OPENING BUCKET:", err)
}
auth := &gocb.ClusterAuthenticator{
Buckets: nil,
Username: "Administrator",
Password: "123456789",
}
err = cluster.Authenticate(auth)
if err != nil {
fmt.Printf("Nosql Database Auth errror : %s", err.Error())
}
// Create a document
key := "goDevguideExampleUpdate"
val := "Retrieve Test Value"
_, err = bucket.Upsert(key, &val, 0)
if err != nil {
fmt.Println("ERRROR CREATING DOCUMENT:", err)
}
// Retrieve Document
var retValue interface{}
_, err = bucket.Get(key, &retValue)
if err != nil {
fmt.Println("ERRROR RETURNING DOCUMENT:", err)
}
fmt.Println("Document Retrieved:", retValue)
// Add something to the value
retValue = retValue.(string) + " with Additional Test Value"
// Replace the existing document
_, err = bucket.Replace(key, &retValue, 0, 0)
if err != nil {
fmt.Println("ERRROR REPLACING DOCUMENT:", err)
}
// Retrieve updated document
_, err = bucket.Get(key, &retValue)
if err != nil {
fmt.Println("ERRROR RETURNING DOCUMENT:", err)
}
fmt.Println("Document Retrieved:", retValue)
// Exiting
fmt.Println("Example Successful - Exiting")
}
Also if i use N1ql to query the document then it works but the functions like Get , Upsert , MulateIn , all of them are giving me time outs
Needs to be refactored to either implement and call Dispose or to call ConnectionBase.Disconnect().
Simon has started on this for Java, we will follow the example for all of the sdk's
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.