Skip to content

Instantly share code, notes, and snippets.

@dblock
Created October 29, 2012 16:52
Show Gist options
  • Save dblock/3974846 to your computer and use it in GitHub Desktop.
Save dblock/3974846 to your computer and use it in GitHub Desktop.
A monkey patch for detecing nil IDs.
require 'mongoid/collection'
module Mongoid
class Collection
alias_method :_update, :update
def update(selector, document, options = {})
document.deep_fetch("_id").each do |value|
if value.nil?
Rails.logger.error "Invalid nil _id in #{document}."
raise "Invalid nil _id in #{document}."
end
end
_update selector, document, options
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment