Last active
March 22, 2018 14:19
-
-
Save GauthamBanasandra/32d5dc09173df5b1af3039f07c7aecf6 to your computer and use it in GitHub Desktop.
Check to see if document exists without retrieving its contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/couchbase/gocb" | |
) | |
func lookupDoc(clusterAddress, bucketName, docId string) (exists bool, err error) { | |
exists = false | |
cluster, err := gocb.Connect(clusterAddress) | |
if err != nil { | |
fmt.Printf("Unable to connect to cluster, err : %v\n", err) | |
return | |
} | |
err = cluster.Authenticate(gocb.PasswordAuthenticator{ | |
Username:"cbadminbucket", | |
Password:"password", | |
}) | |
if err != nil { | |
fmt.Printf("Unable to authenticate , err : %v\n", err) | |
return | |
} | |
bucket, err := cluster.OpenBucket(bucketName, "") | |
defer bucket.Close() | |
if err != nil { | |
fmt.Printf("Error connecting to bucket %s, err : %v\n", bucketName, err) | |
return | |
} | |
var value interface{} | |
_, err = bucket.Get(docId, &value) | |
if err != nil { | |
return | |
} | |
exists = true | |
return | |
} | |
func main() { | |
fmt.Println(lookupDoc("couchbase://172.23.107.182", "src_bucket", "query-testemployee10153.1877827-0")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment