Files
open-im-server/test/mongo/cmd/main.go
T

32 lines
651 B
Go
Raw Normal View History

2022-05-25 17:42:45 +08:00
package main
2022-05-25 17:38:49 +08:00
import (
2022-05-25 17:41:32 +08:00
mongo2 "Open_IM/test/mongo"
2022-05-25 17:38:49 +08:00
"context"
"flag"
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
2022-05-25 17:41:32 +08:00
func init() {
2022-05-25 17:38:49 +08:00
clientOptions := options.Client().ApplyURI("mongodb://127.0.0.1:37017/openIM/?maxPoolSize=100")
2022-05-25 17:46:02 +08:00
var err error
mongo2.Client, err = mongo.Connect(context.TODO(), clientOptions)
2022-05-25 17:38:49 +08:00
if err != nil {
panic(err)
}
2022-05-25 17:46:02 +08:00
err = mongo2.Client.Ping(context.TODO(), nil)
2022-05-25 17:38:49 +08:00
if err != nil {
panic(err)
}
fmt.Println("Connected to MongoDB!")
}
func main() {
userID := flag.String("userID", "", "userID")
flag.Parse()
fmt.Println("userID:", userID)
2022-05-25 17:41:32 +08:00
mongo2.GetUserAllChat(*userID)
2022-05-25 17:38:49 +08:00
}