Skip to content

Instantly share code, notes, and snippets.

@john-morales
Created September 10, 2015 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john-morales/7101f5ad05af25199fd2 to your computer and use it in GitHub Desktop.
Save john-morales/7101f5ad05af25199fd2 to your computer and use it in GitHub Desktop.
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