Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-2686

Allow to external mongo client to session provider.

    • Type: Icon: Task Task
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: mongo-tools-common
    • None

      Allow setting the external mongo client when creating a session provider.

       

      I already have a mongo client i.e created for the application I want to reuse it.

       

      // NewSessionProvider constructs a session provider, including a connected client.
      func NewSessionProvider(opts options.ToolOptions) (*SessionProvider, error) {
         // finalize auth options, filling in missing passwords
         if opts.Auth.ShouldAskForPassword() {
            pass, err := password.Prompt()
            if err != nil {
               return nil, fmt.Errorf("error reading password: %v", err)
            }
            opts.Auth.Password = pass
         }
      
         client, err := configureClient(opts)
         if err != nil {
            return nil, fmt.Errorf("error configuring the connector: %v", err)
         }
         err = client.Connect(context.Background())
         if err != nil {
            return nil, err
         }
         err = client.Ping(context.Background(), nil)
         if err != nil {
            return nil, fmt.Errorf("could not connect to server: %v", err)
         }
      
         // create the provider
         return &SessionProvider{client: client}, nil
      }
      

            Assignee:
            tim.fogarty@mongodb.com Tim Fogarty
            Reporter:
            nsaoly@gmail.com jeet parmar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: