Creates a new document, assigning it a random doc ID.
(ctx context.Context, body Body)
| 3180 | |
| 3181 | // Creates a new document, assigning it a random doc ID. |
| 3182 | func (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. |
| 3205 | func (db *DatabaseCollectionWithUser) DeleteDoc(ctx context.Context, docid string, docVersion DocVersion) (string, *Document, error) { |