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

Method Post

db/crud.go:3182–3202  ·  view source on GitHub ↗

Creates a new document, assigning it a random doc ID.

(ctx context.Context, body Body)

Source from the content-addressed store, hash-verified

3180
3181// Creates a new document, assigning it a random doc ID.
3182func (db *DatabaseCollectionWithUser) Post(ctx context.Context, body Body) (docid string, rev string, doc *Document, err error) {
3183 // This error isn't very accurate, you just _cannot_ use POST to update an existing document - even if it does exist. We don't even bother checking for existence.
3184 if body[BodyRev] != nil || body[BodyCV] != nil {
3185 return "", "", nil, base.HTTPErrorf(http.StatusNotFound, "No previous revision to replace")
3186 }
3187
3188 // If there's an incoming _id property, use that as the doc ID.
3189 docid, idFound := body[BodyId].(string)
3190 if !idFound {
3191 docid, err = base.GenerateRandomID()
3192 if err != nil {
3193 return "", "", nil, err
3194 }
3195 }
3196
3197 rev, doc, err = db.Put(ctx, docid, body)
3198 if err != nil {
3199 docid = ""
3200 }
3201 return docid, rev, doc, err
3202}
3203
3204// Deletes a document, by adding a new revision whose _deleted property is true.
3205func (db *DatabaseCollectionWithUser) DeleteDoc(ctx context.Context, docid string, docVersion DocVersion) (string, *Document, error) {

Callers 8

uploadCACertViaRESTFunction · 0.80
handlePostDocMethod · 0.80
handleBulkDocsMethod · 0.80
HandleEventMethod · 0.80
TestPostWithExistingIdFunction · 0.80
TestWithNullPropertyKeyFunction · 0.80

Calls 3

PutMethod · 0.95
HTTPErrorfFunction · 0.92
GenerateRandomIDFunction · 0.92

Tested by 5

uploadCACertViaRESTFunction · 0.64
TestPostWithExistingIdFunction · 0.64
TestWithNullPropertyKeyFunction · 0.64