-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Creating a custom type for Mongo's ID's #442
Comments
We use |
@pbdeuchler Do you need to manually convert between the two at runtime still? Did you need to limit the bytes to 12 in your protobuf def? |
Oh yeah it is just bytes under the hood! https://godoc.org/github.com/pkg/bson#ObjectId |
Closing this in favor of #52. |
@EwanValentine @pbdeuchler have you tried the official mongodb go driver? I couldn't get it working: |
Hi, look at this one: |
ObjectId can be replaced with a simple string in proto now |
@mihai1voicescu Could you show the example code? Either it doesn't work for me or I didn't get you right. |
Unfortunately I put that project on hold before I could finish but this is what I used:
Which generates:
As far as I remember (so I might be wrong) you are then free to insert the structs in Mongo and it will generate an ID if the
Note that I had one more problem with the ID, but I can't remember what it was or if I solved it. Hope it helps! If not maybe you can post the exact exception/st/problem. Please note that I am not an expert in go so the above code might not be production ready. |
Has this been solved or not yet? |
Apologies, I raised a similar ticket a while back but I just thought I'd raise a more specific question than my previous closed ticket. #393
For some context, when you generate protobuf code, say...
You would get
Which means I have to do a bunch of conversion in order to use these structs as Mongodb models. As Mongodb's mgo driver requires a
bson.ObjectId
custom type for the ID field. Also the ID field is all uppercase as per Golang's own linting/style guide. Whereas protobuf generates them asId
.So given that, is there a way I can create a custom type which would generate mgo compatible ID fields? Such as...
generates...
I just wondered how to go about creating a custom type for this use-case?
I noticed someone had a PR of a similar nature a while back which wasn't approved/merged: #320
Thanks in advance!
The text was updated successfully, but these errors were encountered: