Code modified to run for 2.x to 4.x mongoid versions.