state: don't issue $set/$unset with empty set

Mongo 2.6 complains if you attempt to perform
a $set or $unset operation with an empty set.
If the set is dynamic, we must be careful to
only issue the operation if non-empty.
Refactor to use bson.M, utility function
Merge pull request #488 from axw/state-nosetunsetempty

state: don't issue $set/$unset with empty set

Mongo 2.6 complains if you attempt to perform
a $set or $unset operation with an empty set.
If the set is dynamic, we must be careful to
only issue the operation if non-empty.