Finnnn Finnnn - 1 year ago 107
Ruby Question

Compare string ID to BSON::ObjectId

I have an array of made up of type

and I want it to compare against some IDs as strings.

if my_array_of_BSON_ObjectIds.include?(@my_id_as_a_string)
# delete the item from the array
# add the item to the array as a BSON::ObjectId

This is not working as the types are different, can I turn my string into a
? If so, how?

Answer Source

You can use BSON::ObjectId(@my_id_as_a_string) for representation your id as BSON::ObjectId


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download