Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to remove/delete a collection? #43

Open
maxpaynestory opened this issue Dec 3, 2019 · 1 comment
Open

how to remove/delete a collection? #43

maxpaynestory opened this issue Dec 3, 2019 · 1 comment

Comments

@maxpaynestory
Copy link

I am new to bongo. Could anybody please tell me how to remove/delete a collection?

@yasaricli
Copy link

There are two ways to delete.

If there is a document you want to remove Use DeleteDocument().

or you can use Delete() if you want to remove it with a query.

I can give an example for DeleteDocument as follows.

type User struct {
  bongo.DocumentBase `bson:",inline"`
  UserName           string `json:"username"`
}

// get user
user := &User{}
_ = connection.Collection("people").FindOne(bson.M{
  "username": "test",
}, user)

// DeleteDocument
err = connection.Collection("people").DeleteDocument(user)

log.Println(err)

If you want to remove it with a query, use Delete.

changeInfo, err := connection.Collection("people").Delete(bson.M{
  "username": "test",
})

log.Println(changeInfo, err)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants