MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / GetDocument

Method GetDocument

base/bootstrap.go:452–476  ·  view source on GitHub ↗

GetDocument fetches a document from the default collection. Does not use configPersistence - callers requiring configPersistence handling should use GetMetadataDocument.

(ctx context.Context, bucketName, docID string, rv interface{})

Source from the content-addressed store, hash-verified

450// GetDocument fetches a document from the default collection. Does not use configPersistence - callers
451// requiring configPersistence handling should use GetMetadataDocument.
452func (cc *CouchbaseCluster) GetDocument(ctx context.Context, bucketName, docID string, rv interface{}) (exists bool, err error) {
453 if cc == nil {
454 return false, errors.New("nil CouchbaseCluster")
455 }
456
457 b, teardown, err := cc.getBucket(ctx, bucketName)
458 if err != nil {
459 return false, err
460 }
461
462 defer teardown()
463
464 getOptions := &gocb.GetOptions{
465 Transcoder: NewSGJSONTranscoder(),
466 }
467 getResult, err := b.DefaultCollection().Get(docID, getOptions)
468 if err != nil {
469 if errors.Is(err, gocb.ErrDocumentNotFound) {
470 return false, nil
471 }
472 return false, err
473 }
474 err = getResult.Content(rv)
475 return true, err
476}
477
478// Close calls teardown for any cached buckets and removes from cachedBucketConnections
479func (cc *CouchbaseCluster) Close() {

Callers

nothing calls this directly

Calls 3

getBucketMethod · 0.95
NewSGJSONTranscoderFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected