-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for encoding/decoding strings as ObjectIds #98
Comments
Hi @dambrisco It's not something we've come up against but I can definitely see the use case! I like the tag idea (more than previous suggestions of simply changing an ObjectID to be a string) but how would you handle edge cases like a struct with multiple "this is an ObjectID" tags applied? Typically compile-time errors are preferred but mgo does provide runtime errors for other cases so it might not be a deal breaker. Do you have an idea what the tag would look like? Dom |
@domodwyer I believe multiple ObjectID tags would be admissible. As I imagine it, it functions only as a marshaling hint. Simply calling the tag The largest issue that I'm not sure how we might handle is non-string types. Some types, like |
I like the I hadn't thought about the int case though - you raise a good point. If the user tags it as an It's a good idea! Including it is contingent on having a negligible performance cost but I can't see why that wouldn't be the case. |
Sorry, but what do you think about the |
@dalu Can you elaborate? |
Currently, there's a rather unfortunate side effect of using this library in that you have to go pretty aggressively out of your way to use string-based IDs (especially in the case of microservices leveraging different DBs but using the same model library). One step toward improved support has been implemented in a PR against the originating fork: go-mgo#492
Yet more powerful might be the inclusion of a new tag that indicates that a given string field should be treated as an ObjectId for marshaling purposes.
Is there any resistance to the inclusion of this sort of feature?
The text was updated successfully, but these errors were encountered: