Git Product home page Git Product logo

Comments (10)

tnerolftnerolf avatar tnerolftnerolf commented on September 23, 2024 6

Any news?

from mgo.

simagix avatar simagix commented on September 23, 2024 1

I have switched to the official mongodb-go-driver. Here are some examples to help your transition, https://github.com/simagix/mongo-go-examples/tree/master/examples.

from mgo.

domodwyer avatar domodwyer commented on September 23, 2024

Hi @benweissmann

This sounds like a cool addition and should be relatively easy! We don't have a 3.6 testing environment built up yet but it's in the works, I'll leave this ticket open in the meantime.

Saying that, we'll happily accept a PR for this!

Dom

from mgo.

simagix avatar simagix commented on September 23, 2024

I forked but was not able to run unit tests b/c of the error below.

imports github.com/globalsign/mgo/internal/scram: use of internal package not allowed

Here are the changes to support dns seedlist :

$ git diff session.go
diff --git a/session.go b/session.go
index cd2a53e..488712f 100644
--- a/session.go
+++ b/session.go
@@ -788,7 +788,13 @@ type urlInfoOption struct {
 }

 func extractURL(s string) (*urlInfo, error) {
-       s = strings.TrimPrefix(s, "mongodb://")
+       isSRV := false
+       if strings.Index(s, "mongodb+srv://") == 0 {
+               isSRV = true
+               s = strings.TrimPrefix(s, "mongodb+srv://")
+       } else {
+               s = strings.TrimPrefix(s, "mongodb://")
+       }
        info := &urlInfo{options: []urlInfoOption{}}

        if c := strings.Index(s, "?"); c != -1 {
@@ -824,6 +830,32 @@ func extractURL(s string) (*urlInfo, error) {
                s = s[:c]
        }
        info.addrs = strings.Split(s, ",")
+       if isSRV == true {
+               // auto turn off ssl
+               info.options = append(info.options, urlInfoOption{key: "ssl", value: "true"})
+               srvAddr := info.addrs[0]
+               params, pe := net.LookupTXT(srvAddr)
+               if pe != nil {
+                       return nil, fmt.Errorf(pe.Error())
+               }
+               for _, pair := range strings.FieldsFunc(params[0], isOptSep) {
+                       l := strings.SplitN(pair, "=", 2)
+                       if len(l) != 2 || l[0] == "" || l[1] == "" {
+                               return nil, errors.New("connection option must be key=value: " + pair)
+                       }
+                       info.options = append(info.options, urlInfoOption{key: l[0], value: l[1]})
+               }
+               _, addrs, le := net.LookupSRV("mongodb", "tcp", srvAddr)
+               if le != nil {
+                       return nil, fmt.Errorf(le.Error())
+               }
+               addresses := make([]string, len(addrs))
+               for i, addr := range addrs {
+                       address := strings.TrimSuffix(addr.Target, ".")
+                       addresses[i] = fmt.Sprintf("%s:%d", address, addr.Port)
+               }
+               info.addrs = addresses
+       }
        return info, nil
 }

@@ -2912,7 +2944,6 @@ func (p *Pipe) SetMaxTime(d time.Duration) *Pipe {
        return p
 }

from mgo.

mhutter avatar mhutter commented on September 23, 2024

This would make the MGO driver compatible with MongoDB Atlas

from mgo.

frontmill avatar frontmill commented on September 23, 2024

It would really be great to see this implemented

from mgo.

bonczj avatar bonczj commented on September 23, 2024

I spent some time today porting the logic from the new, official Mongo driver back to mgo. We are running off of master, so I started my branch from there as it makes it easier for us to pick up without grabbing new features off of the development branch.

@maitesin I know that the contributions should be off of release. Before I send a PR over to you, does it have to be against development branch? While I know we are running against master, I don't know what most people are using. It is also unclear if/when a new release will be cut.

from mgo.

slaveofcode avatar slaveofcode commented on September 23, 2024

It's 2021, any updates on this issue?

from mgo.

mhutter avatar mhutter commented on September 23, 2024

Well, there now is an official Driver from MongoDB which also covers this use case.

from mgo.

Neustradamus avatar Neustradamus commented on September 23, 2024

@ all: I wish you a Happy New Year 2022!

Any news about it?

from mgo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.