@@ -64,6 +64,7 @@ type buffer struct {
6464}
6565
6666type conn struct {
67+ adiomv1connect.UnimplementedConnectorServiceHandler
6768 client * mongo.Client
6869
6970 settings ConnectorSettings
@@ -326,6 +327,7 @@ func (c *conn) GetInfo(ctx context.Context, r *connect.Request[adiomv1.GetInfoRe
326327 LsnStream : true ,
327328 MultiNamespacePlan : true ,
328329 DefaultPlan : ! c .settings .PerNamespaceStreams ,
330+ GetByIds : true ,
329331 },
330332 Sink : & adiomv1.Capabilities_Sink {
331333 SupportedDataTypes : []adiomv1.DataType {adiomv1 .DataType_DATA_TYPE_MONGO_BSON },
@@ -1046,3 +1048,48 @@ func maybeUnavailableError(err error) error {
10461048 }
10471049 return connect .NewError (connect .CodeInternal , err )
10481050}
1051+
1052+ // GetByIds implements adiomv1connect.ConnectorServiceHandler.
1053+ func (c * conn ) GetByIds (ctx context.Context , r * connect.Request [adiomv1.GetByIdsRequest ]) (* connect.Response [adiomv1.GetByIdsResponse ], error ) {
1054+ col , _ , ok := GetCol (c .client , r .Msg .GetNamespace ())
1055+ if ! ok {
1056+ return nil , connect .NewError (connect .CodeInvalidArgument , fmt .Errorf ("namespace should be fully qualified" ))
1057+ }
1058+
1059+ // TODO: maybe use batch endpoint if we need to optimize
1060+ res := make ([]* adiomv1.GetByIdsResponse_ResponseItem , len (r .Msg .GetIds ()))
1061+ var eg errgroup.Group
1062+ for i , id := range r .Msg .GetIds () {
1063+ eg .Go (func () error {
1064+ if len (id .GetId ()) < 1 {
1065+ res [i ] = & adiomv1.GetByIdsResponse_ResponseItem {}
1066+ return nil
1067+ }
1068+ bv := id .GetId ()[0 ]
1069+ rawVal := bson.RawValue {
1070+ Type : bsontype .Type (bv .GetType ()),
1071+ Value : bv .GetData (),
1072+ }
1073+ v , err := col .FindOne (ctx , bson.M {"_id" : rawVal }).Raw ()
1074+ if err != nil {
1075+ if errors .Is (err , mongo .ErrNoDocuments ) {
1076+ res [i ] = & adiomv1.GetByIdsResponse_ResponseItem {}
1077+ return nil
1078+ }
1079+ return fmt .Errorf ("err in findone: %w" , err )
1080+ }
1081+ res [i ] = & adiomv1.GetByIdsResponse_ResponseItem {
1082+ Data : v ,
1083+ }
1084+ return nil
1085+ })
1086+ }
1087+
1088+ if err := eg .Wait (); err != nil {
1089+ return nil , connect .NewError (connect .CodeInternal , fmt .Errorf ("err finding ids: %w" , err ))
1090+ }
1091+
1092+ return connect .NewResponse (& adiomv1.GetByIdsResponse {
1093+ Data : res ,
1094+ }), nil
1095+ }
0 commit comments