SHARE
TWEET

Untitled

a guest Oct 4th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "time"
  6.     "gopkg.in/mgo.v2"
  7. )
  8.  
  9. //const MongoDb details
  10. const (
  11.     mongoDBhosts = "localhost:27017"
  12.     mongoDBBase = "<base_name>"
  13.     mongoUserName = "<user_name>"
  14.     mongoDBPassword = "<user_password>"
  15.     mongoDBCollection = "<collection_name>"
  16. )
  17.  
  18. func main() {
  19.     mongoDBinfo := &mgo.DialInfo{Addrs: []string{mongoDBhosts}, Timeout: 60 * time.Second, Database: database,  Username: mongoUserName, Password: mongoDBPassword,}
  20.  
  21.     session, err := mgo.DialWithInfo(mongoDBinfo)
  22.     if err != nil {
  23.         panic(err)
  24.     }
  25.  
  26.     col := session.DB(mongoDBBase).C(mongoDBCollection)
  27.  
  28.     count, err2 := col.Count()
  29.     if err2 != nil {
  30.         panic(err2)
  31.     }
  32.     fmt.Println(fmt.Sprintf("Messages count: %d", count))
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top