I am using grpc
+golang
+mongodb
, and I have the following proto
file.
enum InventoryType {
LARGE = 0;
SMALL = 1;
}
my go code:
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"inventory-service/pb"
)
func (i *Inventory) CreateInventory(ctx context.Context, req *pb.CreateInventoryRequest) (*pb.CreateInventoryResponse, error) {
inventory := req.GetInventory()
data := pb.Inventory{
Inventory: inventory.GetInventory(),
}
mctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
client, _ := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
collection := client.Database("test_db").Collection("test_collection")
collection.InsertOne(mctx, data)
return &pb.CreateInventoryResponse{}, nil
}
and when I save the enum to mongodb using golang, it saves the int value 0, 1 instead of 'LARGE', 'SMALL', any ideas on how I can save string instead?