Fix issues with deleting memberships

Not sure why this has stopped working but if you use .nin or $nin in a
where and then tack on a remove, or use them in a remove then it
produces an error about there being a $ in the key. To fix this do the
where then explicitely remove all the returned memberships.

Fixes #666