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{})
| 450 | // GetDocument fetches a document from the default collection. Does not use configPersistence - callers |
| 451 | // requiring configPersistence handling should use GetMetadataDocument. |
| 452 | func (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 |
| 479 | func (cc *CouchbaseCluster) Close() { |
nothing calls this directly
no test coverage detected