Imports a document that was written by someone other than sync gateway, given the existing state of the doc in raw bytes
(ctx context.Context, docid string, value []byte, xattrs map[string][]byte, importOpts importDocOptions, cas uint64)
| 40 | |
| 41 | // Imports a document that was written by someone other than sync gateway, given the existing state of the doc in raw bytes |
| 42 | func (db *DatabaseCollectionWithUser) ImportDocRaw(ctx context.Context, docid string, value []byte, xattrs map[string][]byte, importOpts importDocOptions, cas uint64) (docOut *Document, err error) { |
| 43 | |
| 44 | var body Body |
| 45 | if importOpts.isDelete { |
| 46 | body = Body{} |
| 47 | } else { |
| 48 | err := body.Unmarshal(value) |
| 49 | if err != nil { |
| 50 | db.dbStats().SharedBucketImport().ImportErrorCount.Add(1) |
| 51 | base.InfofCtx(ctx, base.KeyImport, "Unmarshal error during importDoc %v", err) |
| 52 | return nil, base.HTTPErrorf(http.StatusNotFound, "Error unmarshalling %s: %s", base.UD(docid).Redact(), err) |
| 53 | } |
| 54 | |
| 55 | err = validateImportBody(body) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | delete(body, BodyPurged) |
| 60 | } |
| 61 | |
| 62 | existingBucketDoc := &sgbucket.BucketDocument{ |
| 63 | Body: value, |
| 64 | Xattrs: xattrs, |
| 65 | Cas: cas, |
| 66 | } |
| 67 | |
| 68 | return db.importDoc(ctx, docid, body, importOpts.expiry, importOpts.isDelete, importOpts.revSeqNo, existingBucketDoc, importOpts.mode) |
| 69 | } |
| 70 | |
| 71 | // Import a document, given the existing state of the doc in *document format. |
| 72 | func (db *DatabaseCollectionWithUser) ImportDoc(ctx context.Context, docid string, existingDoc *Document, importOpts importDocOptions) (docOut *Document, err error) { |