One should be aware when using ! methods (slice!, map!, etc!) on the collections returned from Mongoid queries ie:

¬†foos does not have foo1..3 shifted from the array as you’d expect, it’s state has not been mutated.

I’m not sure if this is by design or otherwise (it most certainly is a by-product of the lazily evaluated nature of Mongoid queries, but for the time being

foos = foos.to_a; foos.slice!(0,3)

will do the trick.

Just something to look out for!

blog comments powered by Disqus