There have been several inquiries/requests to improve symbol handling in Mongoid. In Ruby, Symbol is a valid and commonly used type, and currently there isn't a great way to work with symbols in Ruby code while persisting them in MongoDB in a way that is interoperable with other drivers and does not use deprecated functionality like the bson symbol type.
This ticket proposes adding a StringifiedSymbol field type to Mongoid, which will behave as follows:
- The value is stored in MongoDB as a string.
- The value is exposed to Ruby applications as a symbol.
Because this will be a new field, we can also add some migration assistance logic as follows:
- If the field reads a bson symbol value out of MongoDB, it is exposed to the applications as a symbol.
- Writes always use the string type.
In this way applications can replace their existing Symbol types with StringifiedSymbol and have the data be gradually converted upon writes. Similarly an application can use StringifiedSymbol to work with data that is also read/written by other languages (where it would be presented as strings).