diff --git a/options.go b/options.go index 44f9e78..a3c8f23 100644 --- a/options.go +++ b/options.go @@ -24,10 +24,10 @@ func GetAllReplicaOptions(o *document.DocumentGetAllReplicaOptions) *gocb.GetAll // GetOptions func GetOptions(o *document.DocumentGetOptions) *gocb.GetOptions { if o == nil { - return &gocb.GetOptions{Transcoder: gocb.NewRawJSONTranscoder()} + return &gocb.GetOptions{Transcoder: gocb.NewRawStringTranscoder()} } return &gocb.GetOptions{ - Transcoder: gocb.NewRawJSONTranscoder(), + Transcoder: gocb.NewRawStringTranscoder(), WithExpiry: o.WithExpiry, Project: o.Project, // ... @@ -67,7 +67,7 @@ func GetAnyReplicaOptions(o *document.DocumentGetAnyReplicaOptions) *gocb.GetAny // InsertOptions func InsertOptions(o *document.DocumentInsertOptions) *gocb.InsertOptions { if o == nil { - return &gocb.InsertOptions{Transcoder: gocb.NewRawJSONTranscoder()} + return &gocb.InsertOptions{Transcoder: gocb.NewRawStringTranscoder()} } return &gocb.InsertOptions{ Timeout: time.Duration(*o.TimeoutNs), @@ -92,6 +92,7 @@ func ReplaceOptions(o *document.DocumentReplaceOptions) *gocb.ReplaceOptions { } return &gocb.ReplaceOptions{ Timeout: time.Duration(*o.TimeoutNs), + Transcoder: gocb.NewRawStringTranscoder(), } } @@ -118,7 +119,7 @@ func UnlockOptions(o *document.DocumentUnlockOptions) *gocb.UnlockOptions { // UpsertOptions func UpsertOptions(o *document.DocumentUpsertOptions) *gocb.UpsertOptions { if o == nil { - return &gocb.UpsertOptions{Transcoder: gocb.NewRawJSONTranscoder()} + return &gocb.UpsertOptions{Transcoder: gocb.NewRawStringTranscoder()} } return &gocb.UpsertOptions{} } diff --git a/provider.go b/provider.go index 46b86fe..0bafe0a 100644 --- a/provider.go +++ b/provider.go @@ -141,7 +141,11 @@ func (h *Handler) Insert(ctx context.Context, id string, doc *types.Document, op result, err := collection.Insert(id, docToInsert, InsertOptions(options)) if err != nil { h.Logger.Error("Error inserting document", "error", err) - return Err[types.MutationMetadata](*types.NewDocumentErrorInvalidValue()), err + if errors.Is(err, gocb.ErrDocumentExists) { + return Err[types.MutationMetadata](*types.NewDocumentErrorAlreadyExists()), nil + } else { + return Err[types.MutationMetadata](*types.NewDocumentErrorInvalidValue()), nil + } } return Ok(MutationMetadata(result)), nil } @@ -168,7 +172,14 @@ func (h *Handler) Replace(ctx context.Context, id string, doc *types.Document, o h.Logger.Error("Error fetching collection from context", "error", err) return nil, err } - result, err := collection.Replace(id, doc, ReplaceOptions(options)) + + replacement, ok := doc.GetRaw() + if !ok { + h.Logger.Error("Error getting raw document", "doc", doc) + return Err[types.MutationMetadata](*types.NewDocumentErrorNotJson()), nil + } + + result, err := collection.Replace(id, replacement, ReplaceOptions(options)) if err != nil { h.Logger.Error("Error replacing document", "error", err) return nil, err diff --git a/results.go b/results.go index 4dc11d7..ff88e49 100644 --- a/results.go +++ b/results.go @@ -35,7 +35,7 @@ func GetResult(result *gocb.GetResult) (document.DocumentGetResult, error) { } expiresInNs := uint64(result.ExpiryTime().Nanosecond()) returnDoc := document.Document{} - returnDoc.SetRaw(content) + returnDoc.SetRaw(string(content)) return document.DocumentGetResult{ Document: &returnDoc, ExpiresInNs: &expiresInNs,