Wednesday, 14 October 2015

Convert BSON::ObjectId to string and string to BSON::ObjectId


Convert BSON::ObjectId to string:
1.9.3-p125 :080 > profile = Profile.last.id
=> BSON::ObjectId(‘4fe969dd79216d0af9000002’)
1.9.3-p125 :083 > profile_id = profile.to_s
=> “4fe969dd79216d0af9000002”

Convert string to BSON::ObjectId:
1.9.3-p125 :084 > BSON::ObjectId.from_string(profile_id)
 => BSON::ObjectId(‘4fe969dd79216d0af9000002’)

No comments:

Post a Comment