-
-
Save john-morales/7101f5ad05af25199fd2 to your computer and use it in GitHub Desktop.
Go clusterMonitor repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"gopkg.in/mgo.v2" | |
"gopkg.in/mgo.v2/bson" | |
"log" | |
"os" | |
"time" | |
) | |
func main() { | |
mgo.SetDebug(true) | |
var aLogger *log.Logger | |
aLogger = log.New(os.Stderr, "", log.LstdFlags) | |
mgo.SetLogger(aLogger) | |
dialInfo := &mgo.DialInfo{ | |
Addrs: []string{"localhost:6000"}, | |
Direct: true, | |
Timeout: 4 * time.Second, | |
FailFast: true, | |
Username: "usernameWithClusterMonitorRole", | |
Password: "password", | |
Source: "admin", | |
Mechanism: "SCRAM-SHA-1", | |
} | |
session, err := mgo.DialWithInfo(dialInfo) | |
if err != nil { | |
panic(err) | |
} | |
defer session.Close() | |
session.SetMode(mgo.Eventual, true) | |
coll := session.DB("test").C("system.profile") | |
profileData := make([]bson.D, 0) | |
if err := coll.Find(nil).Limit(20).Sort("-$natural").All(&profileData); err != nil { | |
panic(err) | |
} | |
fmt.Printf("Found %d test entries\n", len(profileData)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment