fix(api): delete url from database

This commit is contained in:
Medzik 2021-08-01 18:26:48 +00:00
parent 8d901b1160
commit b8f70413cf
2 changed files with 9 additions and 5 deletions

View File

@ -2,8 +2,10 @@ package mongo
import (
"context"
"fmt"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
@ -11,9 +13,11 @@ func Delete(url string) (*mongo.DeleteResult, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result, err := Coll.DeleteOne(ctx, json{
"url": url,
})
r, err := Coll.DeleteOne(ctx, bson.M{"_id": url})
if err != nil {
fmt.Print(err)
return nil, err
}
return result, err
return r, err
}

View File

@ -28,7 +28,7 @@ func Delete(c *gin.Context) {
if r.DeletedCount <= 0 {
c.JSON(http.StatusNotFound, json{
"success": false,
"message": "Not found!",
"message": "Not Found!",
})
return