GO SDK Insert Question

Dear all,

I’m starting to look at Couchbase and tried to create and Bucket and insert documents into it.
Unfortunattely I do not get any error and no documents are inserted. Any idea where I should start from?

This is my Go Sample Code:
package main

import (
github.com/couchbase/gocb
“log”
github.com/google/uuid
“fmt”
)

var globalCluster *gocb.Cluster = nil
var globalBucket *gocb.Bucket = nil

func main() {
globalCluster, err := gocb.Connect(“couchbase://localhost”)
if err!=nil{
log.Panic(err)
}
err = globalCluster.Authenticate(gocb.PasswordAuthenticator{“admin”,“password”})
if err!=nil{
log.Panic(err)
}
globalBucket,err = globalCluster.OpenBucket(“property”,"")
if err!=nil{
log.Panic(err)
}
propertyID := uuid.New().String()
property := &Property{“This is my name”}
globalBucket.Insert(propertyID,property,0)
var newProperty Property
globalBucket.Get(propertyID,&newProperty)
fmt.Print(newProperty)

}

type Property struct {
Name string json:"name"
}

Thanks for any help.

Regards,

Hi Alexandre,

I think that you have a syntax error in your Property struct, I was unable to run your sample until I changed it to

type Property struct {
    Name string `json:"name"`
}

After that it ran fine for me and inserted the document. You could also try to check for errors on the Insert and Get commands:

_, err = globalBucket.Insert(propertyID, property, 0)
1 Like