Skip to content

Commit

Permalink
Instead use mongo driver
Browse files Browse the repository at this point in the history
  • Loading branch information
vanshaj committed Dec 24, 2021
1 parent 015ec15 commit bef598a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions blackhatgo/chapter7/mongoCon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"fmt"
"log"

"github.com/globalsign/mgo"
)

type user struct {
name string `bson:"name"`
lastname string `bson:"lastname"`
age int `bson:"age"`
}

func main() {
session, err := mgo.Dial("127.0.0.1:27017")
if err != nil {
log.Panicln(err)
}
defer session.Close()

result := make([]user, 2)

if err := session.DB("mydb").C("trans").Find(nil).All(&result); err != nil {
log.Panicln(err)
}
for _, res := range result {
fmt.Println(res.age)
fmt.Println(res.name)
fmt.Println(res.lastname)
}

}

0 comments on commit bef598a

Please sign in to comment.