MongoDB
package main
import (
"context"
"github.com/joshqu1985/fireman/configor"
"github.com/joshqu1985/fireman/store/mongo"
)
type Config struct {
Mongo mongo.Config
}
var (
Conf Config
)
func init() {
if err := configor.Load("./configs/conf.toml", &Conf); err != nil {
panic(err)
}
}
type Summary struct {
ObjectId string `json:"object_id" bson:"object_id"`
CommsCount int `json:"comms_count" bson:"comms_count"`
CommsFirstCount int `json:"comms_first_count" bson:"comms_first_count"`
LikesCount int `json:"likes_count" bson:"likes_count"`
RepostsCount int `json:"reposts_count" bson:"reposts_count"`
IsLiking bool `json:"is_liking" bson:"is_liking,omitempty"`
}
func main() {
pool := mongo.NewPool(Conf.Mongo)
item := &Summary{}
handle := func(c *mongo.Collection) error {
return c.Find(mongo.M{"object_id": objectId}).One(item)
}
err := pool.DB("BoardSummary").Doit(ctx, "summary", handle)
fmt.Prinln(item, err)
}
#conf.toml
[mongo]
host = "127.0.0.1:27017"
auth = "" # "test:BwUSdSQxtUx@"
opts = "minPoolSize=0&maxIdleTimeMS=3000"
database = ["BoardComment", "BoardLike", "BoardSummary"]