1

Currently I already use NewRegistryBuilder() in the mongo client options , Somehow i want to make use of NewRespectNilValuesRegistryBuilder() from mongocompact so that I can set the nilvalues in the []models as empty array .

Currently I have something like below , To map the old mgo behavior

tM := reflect.TypeOf(bson.M{})
registry := bson.NewRegistryBuilder().RegisterTypeMapEntry(bsontype.EmbeddedDocument, tM).Build()
clientOpts := options.Client().ApplyURI(URI).SetAuth(info).SetRegistry(registry)
client, err := mongo.Connect(ctx, clientOpts)

Now somehow I want to incorporate and set the NewRespectNilValuesRegistryBuilder().Build() to true in the same connect options , Not sure how to do that . Also the other problem that i see is i'm not able to see the mongocompat registry file in my vendor directory

can i do something like this , SetRegistry() two times ? like below ?

tM := reflect.TypeOf(bson.M{})
registry := bson.NewRegistryBuilder().RegisterTypeMapEntry(bsontype.EmbeddedDocument, tM).Build()
clientOpts := options.Client().ApplyURI(SOMEURI).SetAuth(info).SetRegistry(registry)
//not sure if the below line is of right usage ??
clientOpts.SetRegistry(NewRespectNilValuesRegistryBuilder().Build())
client, err := mongo.Connect(ctx, clientOpts)

can anyone help me with this ?

related issue here

Gopher_k
  • 273
  • 2
  • 9

1 Answers1

0

I found a solution to this one , All we need to do is

registry := mgocompat.NewRegistryBuilder().Build()
connectOpts := options.Client().ApplyURI(SOMEURI).SetAuth(info).SetRegistry(registry)

This will take care of both requirements , no need to say

tM := reflect.TypeOf(bson.M{})

Since that's a default behavior that's included in mgocompat

Gopher_k
  • 273
  • 2
  • 9