Created
September 9, 2011 09:46
-
-
Save mostlyobvious/1205853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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