go-bongo / bongo

Go ODM for MongoDB
MIT License
487 stars 40 forks source link

How do I attach afterSave hook? #9

Closed genxstylez closed 7 years ago

genxstylez commented 8 years ago

Can you give me a simple example?

Thanks

yaronius commented 7 years ago

Strange that nobody has answered this question yet. Your document must comply with the AfterSaveHook interface (declared in collection.go). It means that you should only add AfterSave(*Collection) method, something like this:

type Person struct {
        // ... same as in example
}

func (doc *Person) AfterSave(c *bongo.Collection) error {
        // do something
        return nil
}