Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions common/community_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/pem"
"fmt"
"io/ioutil"
"net/url"
neturl "net/url"
"strings"
"time"

Expand Down Expand Up @@ -85,8 +85,11 @@ func NewMongoCommunityConn(url string, connectMode string, timeout bool, readCon
}
l.Logger.Debugf("encodedURL:[%v]", encodedURL)

isSrvURI := strings.HasPrefix(url, "mongodb+srv://")
clientOps := options.Client().ApplyURI(encodedURL)
//clientOps := options.Client().ApplyURI(url)
if !isSrvURI {
clientOps.SetDirect(true)
}
Comment on lines +88 to +92

// tls tlsInsecure + tlsCaFile
if sslRootFile != "" {
Expand Down Expand Up @@ -146,13 +149,10 @@ func NewMongoCommunityConn(url string, connectMode string, timeout bool, readCon
ctx := context.Background()

// connect
client, err := mongo.NewClient(clientOps)
client, err := mongo.Connect(ctx, clientOps)
if err != nil {
return nil, fmt.Errorf("new client failed: %v", err)
}
if err := client.Connect(ctx); err != nil {
return nil, fmt.Errorf("connect to %s failed: %v", BlockMongoUrlPassword(url, "***"), err)
}

// ping
if err = client.Ping(ctx, clientOps.ReadPreference); err != nil {
Expand Down Expand Up @@ -287,7 +287,7 @@ func EncodeMongoURI(uri string) (string, error) {
return "", fmt.Errorf("invalid URI scheme")
}
scheme := parts[0]
if scheme != "mongodb" {
if scheme != "mongodb" && scheme != "mongodb+srv" {
return "", fmt.Errorf("unsupported scheme: %s", scheme)
}
rest := parts[1][2:] // remove "//"
Expand Down Expand Up @@ -315,19 +315,25 @@ func EncodeMongoURI(uri string) (string, error) {
// split hosts and path
hostPathParts := strings.SplitN(afterUserInfo, "/", 2)
host := hostPathParts[0]
var path string

var path, rawQuery string
if len(hostPathParts) > 1 {
path = "/" + hostPathParts[1]
} else {
path = ""
pathAndQuery := hostPathParts[1]
// split path and query
pathQueryParts := strings.SplitN(pathAndQuery, "?", 2)
path = "/" + pathQueryParts[0]
if len(pathQueryParts) > 1 {
rawQuery = pathQueryParts[1]
}
}
Comment on lines 316 to 328

// generate URL
u := &url.URL{
Scheme: scheme,
User: url.UserPassword(username, password),
Host: host,
Path: path,
u := &neturl.URL{
Scheme: scheme,
User: neturl.UserPassword(username, password),
Host: host,
Path: path,
RawQuery: rawQuery,
}

return u.String(), nil
Expand Down
1 change: 1 addition & 0 deletions logs/mongoshake.pid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
144794
19 changes: 19 additions & 0 deletions mongoshake.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#conf.version = 11

#mongo_urls = mongodb://root:O249MCkl.~laPeNe@10.2.0.216:30310/?directConnection=true
#mongo_urls = mongodb://root:O249MCkl.~laPeNe@10.42.0.96:27017,10.42.0.97:27017/?replicaSet=rs1
#mongo_urls = mongodb://root:O249MCkl.~laPeNe@127.0.0.1:27017/admin?directConnection=true
#mongo_urls = mongodb://msuser:MySafePassword123!@127.0.0.1:27018/admin?authSource=admin&directConnection=true
#tunnel.address = mongodb://root:b841Pt6cOrMppzmX@10.2.0.216:32255
Comment on lines +3 to +7

#filter.namespace.black = config,local

#sync_mode = all


conf.version = 11
mongo_urls =
tunnel.address= mongodb://root:YcYbhFKuCwso~CxL@10.2.0.216:30378
sync_mode = all
full_sync.executor.insert_on_dup_update = true

Loading