Skip to content

Instantly share code, notes, and snippets.

@MatthewRDodds
Last active August 29, 2015 14:19
Show Gist options
  • Save MatthewRDodds/b6f7dbc01b4b23d87565 to your computer and use it in GitHub Desktop.
Save MatthewRDodds/b6f7dbc01b4b23d87565 to your computer and use it in GitHub Desktop.
Ruby Converting From String to BSON::ObjectId and From BSON::ObjectId to String
pry(main)> id
=> BSON::ObjectId('5537c5a93338660008010000')
pry(main)> id.to_s # Converting to string
=> "5537c5a93338660008010000"
pry(main)> BSON::ObjectId.from_string id.to_s # Converting from String
=> BSON::ObjectId('5537c5a93338660008010000')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment