Skip to content

Instantly share code, notes, and snippets.

@mostlyobvious
Created September 9, 2011 09:46
Show Gist options
  • Save mostlyobvious/1205853 to your computer and use it in GitHub Desktop.
Save mostlyobvious/1205853 to your computer and use it in GitHub Desktop.
def has_id?(doc)
# mongo-ruby-driver seems to take :_id over '_id' for some reason
id = doc[:_id] || doc['_id']
return id if id
nil
end
def sanitize_id!(doc)
doc[:_id] = has_id?(doc) || BSON::ObjectId.new
doc.delete('_id')
doc
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment