title: Executing raw MongoDB queries in Rails controller
body: <p>I have the follow raw mongo query that I want to execute directly in my Rails controller:</p>
  
  <pre><code> db.user_places.update({place_id: destroy_model.id}, {$set: {place_id: keep_model.id}}, false, true)
  </code></pre>
  
  <p>For sequel, I was using <code>ActiveRecord::Base.connection.execute(sql)</code> to execute my sql queries.</p>
  
  <p>What's the equivalent way of doing this using MongoDB/mongoid gem? I've tried following <a href="https://stackoverflow.com/questions/6548061/how-to-fire-raw-mongodb-queries-directly-in-ruby">How to fire raw MongoDB queries directly in Ruby</a>,  but I'm not using MongoMapper.</p>
  
  <p>Thank you.</p>
  
  <p>Edit: My solution to this problem was to just run the following from Mongoid documentation:</p>
  
  <p><code>UserPlace.where(place_id: destroy_model.id).update_all(place_id: keep_model.id)</code></p>
  
  <p>This will generate the raw mongo query above and execute it in ActiveRecord fashion.</p>