Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "time"
- "gopkg.in/mgo.v2"
- )
- //const MongoDb details
- const (
- mongoDBhosts = "localhost:27017"
- mongoDBBase = "<base_name>"
- mongoUserName = "<user_name>"
- mongoDBPassword = "<user_password>"
- mongoDBCollection = "<collection_name>"
- )
- func main() {
- mongoDBinfo := &mgo.DialInfo{Addrs: []string{mongoDBhosts}, Timeout: 60 * time.Second, Database: database, Username: mongoUserName, Password: mongoDBPassword,}
- session, err := mgo.DialWithInfo(mongoDBinfo)
- if err != nil {
- panic(err)
- }
- col := session.DB(mongoDBBase).C(mongoDBCollection)
- count, err2 := col.Count()
- if err2 != nil {
- panic(err2)
- }
- fmt.Println(fmt.Sprintf("Messages count: %d", count))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement