oh oh
package config
import (
"fmt"
// _ "github.com/lib/pq"
"gopkg.in/mgo.v2"
"time"
)
// database
var DBmgo *mgo.Database
// collections
var UserAgent *mgo.Collection
func init() {
info := &mgo.DialInfo{
Addrs: []string{"ip:port"},
Timeout: 1 * time.Hour,
Database: "name db",
Username: "user",
Password: "pass",
//Source: "admin",
Mechanism: "SCRAM-SHA-1",
}
s, err := mgo.DialWithInfo(info)
if err != nil {
panic(err)
}
if err = s.Ping(); err != nil {
panic(err)
}
DBmgo = s.DB("name db")
UserAgent = DBmgo.C("collection")
fmt.Println("You connected to your mongo database.")
}
On Wednesday, September 5, 2018 at 10:07:08 PM UTC+7, Kathiresh Kumar wrote:
>
> How can I connect golang with mongoDB????
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.