Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Go clusterMonitor repro
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
You can’t perform that action at this time.