globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

Soft delete feature #169

Closed TheWrongAlice closed 6 years ago

TheWrongAlice commented 6 years ago

I made this for use in my project, I don't know if it's something you want maybe?

If Collection.UsesSoftDelete flag is set to true, it changes the behaviour for functions Find, FindId, Remove, RemoveId, RemoveAll.

Remove functions will not delete from database, instead they add a new property deleted: true. Find" functions will ignore all that has the deleted: true flag. I plan to expand this with an Restore function that removes the deleted flag.

Also I could not figure out how to run the unit tests for my own repo, but I guess this pull request will run them for me :ok_hand:

domodwyer commented 6 years ago

Hi @TheWrongAlice

It's a nice idea and definitely would save some boilerplate for others, but it crosses driver / ORM library boundary a bit - we typically avoid this library dictating any document content and keep it strictly on the driver side for maximum flexibility.

I fully agree it's of great use to a lot of people though - have you considered wrapping it up as an ORM package that builds on top of mgo? A mongo ORM could go down rather well.

Thanks for taking the time to open a PR though, it's genuinely appreciated!

Dom