We are currently migrating from MySQL to MongoDB, and I stumbled over the following:
MyModel.destroy(params[model_ids]) # Remove many objects at once by passing an array of IDs
This worked for ActiveRecord, but for MongoDB it doesn’t: I have to iterate over the IDs, find it, and then call the delete method on the instantiated object:
MyModel.find(params[model_ids]).each do |item|
item.destroy
end
Is this the correct way to go? And is there a special reason why Mongoid doesn’t offer the mentioned functionality?
Thank you!
You can try this
In Mongoid you can run the destroy method on a criteria.