Comments (10)
Any news?
from mgo.
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.
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.
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.
This would make the MGO driver compatible with MongoDB Atlas
from mgo.
It would really be great to see this implemented
from mgo.
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.
It's 2021, any updates on this issue?
from mgo.
Well, there now is an official Driver from MongoDB which also covers this use case.
from mgo.
@ all: I wish you a Happy New Year 2022!
Any news about it?
from mgo.
Related Issues (20)
- Query blocks with ChangeStream HOT 2
- Upsert doesn't work well with query where value is []byte format
- Expose dialInfo through a getter?
- High concurrency session copy does not release the connection and poolLimit is invalid
- Request: BSON stabilize ordering of map keys (instead of GoLang's random ordering) HOT 1
- Unwanted allocs in mgo
- Auto type assertion not working when fetching data
- Clean actions attribute of Bulk struct
- time.Parse HOT 2
- can any one tell me how to use $near to calculate lat,lng distance
- MongoDB index not being used when querying through mgo on mongoDB views
- }
- DropDatabase returns not master when seesion mode is Secondary
- mgo: FindAndModify create too many sockets
- error="SASL support not enabled during build (-tags sasl)" HOT 8
- Daemontools
- Panic With ObjectIdHex(s string)
- current
- BSON unmarshal unable to parse $date
- error="no reachable servers" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mgo.