pie is a wrapper based on the official mongo-go-driver, all operations are done through chain calls, making it easy to operate MongoDB.
go get github.com/5xxxx/pie
package main
import (
"github.com/5xxxx/pie"
"go.mongodb.org/mongo-driver/mongo/options"
)
client, err := pie.NewClient(cfg.DataBase, options.Client().ApplyURI("mongodb://127.0.0.1:27017"))
if err != nil {
panic(err)
}
err = t.Connect(context.Background())
if err != nil {
panic(err)
}
var user User
err = t.filter("nickName", "frank").FindOne(&user)
if err != nil {
panic(err)
}
fmt.Println(user)