I have a requirement to store the content of proto to mongoDB for which I am converting proto to json string and then converting to Document object.
Some time the proto will have so much data upto 14mb which makes the above conversion takes around 5 seconds, which is causing too much of latency in the code. Is their a better way to handle this ?
MongoDB Bson has the limit of 16 mb but this conversion comes with latency.
> private static Document serialize(AggregationProto aggregationProto) {
try { String json = JsonFormat.printer().print(aggregationProto); return Document.parse(json); } catch (InvalidProtocolBufferException e) { throw new IllegalStateException("Failed to print aggregationProto as JSON", e); }
Above is the method used to convert from proto to MongoDB Document.
Overall I am looking for something like below:
(proto <=> bson instead of proto <=> json <=> bson)
Reference: protocol buffers - Straightforward way to store protobuf java object in Mongodb? - Stack Overflow
Anything updated after this: BSON <=> google::protobuf::Message · Issue #2601 · protocolbuffers/protobuf · GitHub
DB update takes 2 sec and serialization takes 2 sec = total 4 sec.
How can this be improved?