Use custom deployment in ClientOptions return error

When i convert-standalone-to-replica-set , use custom deployment in clientOptions when create mongo Client, I got such error like cannot specify topology or server options with a deployment , Below is the error link return in mongo-go-driver source code, the length topologyOpts slice is greater than four in my situation( opts.ReplicaSet is not nil) which result in the problem

I have read the whole configure function in client.go source code, the minimun elements in topologyOpts is four, if clientOptions object have nonempty atrributes like Direct | ReplicaSet |ServerMonitor| ServerSelectionTimeout| LoadBalanced , topologyOpts elements will get increased 。 meanwhile, if you use custom deployment in clientOptions, you will encouter the error describe before, But if i comment the topologyOpts length compare in mongo-go-driver code, my program can still work。 I have searched the first commit of this line code in Change Client to depend on driver.Deployment · mongodb/mongo-go-driver@bb9530d · GitHub ,still could not get some helpful msg

question:
Is there any real use of the limitation of the topologyOpts length? i can not figure out,Or limitation of the topologyOpts length is not correct in the code?

Hey @fleetingtimer_N_A thanks for the question! What is your use case for defining a custom Deployment?

The purpose of the serverOpts and topologyOpts length checks is to prevent specifying any non-default options, which won’t be honored if a custom Deployment is used. However, I strongly recommend against using a custom Deployment because you’re likely to encounter undefined behavior. The documentation of ClientOptions says that the Deployment configuration is not intended for use except for internal use cases (e.g. Go Driver tests):

// Deployment specifies a custom deployment to use for the new Client.
//
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
// release.
Deployment driver.Deployment

Many thanks to you answer, we use custom deployment for support muliti tenant access mongodb sutiation。 I have already read the documentation of [ClientOptions] (options package - go.mongodb.org/mongo-driver/mongo/options - Go Packages) and knew that it is not recommend to use custom deployment,but in my sutiation,self custom deployment generated use the same method with inner deployement https://github.com/mongodb/mongo-go-driver/blob/v1.8.2/mongo/client.go#L138, there should not cause any non-default options. when i use default mongo client generate method without using custom Deployment in mongodb replicaset, the topologyOpts length used for generate deployement is not limited ( may larger than 4 ) and it can work well

@fleetingtimer_N_A thanks for describing your use case more, it sounds like there is no way to accomplish what you’re trying to do without using a custom Deployment.

If you’re not setting any server or topology options in your ClientOptions configuration, you shouldn’t be getting that error message. Can you share an example of your ClientOptions configuration so I can try to reproduce your issue?

Thanks :smiley:, I use a test function as an example of my use case, you may get the test code at Go Playground - The Go Programming Language and put it at https://github.com/mongodb/mongo-go-driver/blob/v1.8.2/mongo/client_test.go file