| 1 |
package apimethods |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
"fsutils" |
| 7 |
firestore "go-genproto/googleapis/firestore/v1beta1" |
| 8 |
"userutil" |
| 9 |
) |
| 10 |
|
| 11 |
//DeleteDocument ... Delete a document from database |
| 12 |
func DeleteDocument() { |
| 13 |
fmt.Println("\n:: Deleting a Document ::\n") |
| 14 |
client, conn := fsutils.MakeFSClient() |
| 15 |
|
| 16 |
defer conn.Close() |
| 17 |
|
| 18 |
fmt.Print("Enter Document Name: ") |
| 19 |
docName := "projects/firestoretestclient/databases/(default)/documents/GrpcTestData/" + userutil.ReadFromConsole() |
| 20 |
|
| 21 |
delDocRequest := firestore.DeleteDocumentRequest{ |
| 22 |
Name: docName, |
| 23 |
} |
| 24 |
|
| 25 |
_, err := client.DeleteDocument(context.Background(), &delDocRequest) |
| 26 |
|
| 27 |
if err != nil { |
| 28 |
fmt.Println(err) |
| 29 |
return |
| 30 |
} |
| 31 |
|
| 32 |
fmt.Println("Successfully Deleted ", docName) |
| 33 |
} |