-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Consider the following models
class User include Mongoid::Document has_and_belongs_to_many :tags, inverse_of: nil field :email field :social_profile # ... other user fields end class Tag include Mongoid::Document # ... tag fields, nothing fancy here end
The following code updates the social_profile field using only to limit the amount of data loaded
User.where(social_profile: nil).only(:email).each do |user| user.social_profile = lookup_service.load_profile(user.email) user.save! end
This loop results in tags being reset on all matching users except for the first one. FWIW it used to keep tags for all users in Mongoid 2.x