You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/test/mongo/mongo_utils.go

46 lines
1.2 KiB

2 years ago
package mongo
import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/db"
server_api_params "Open_IM/pkg/proto/sdk_ws"
"context"
"fmt"
"github.com/golang/protobuf/proto"
2 years ago
"go.mongodb.org/mongo-driver/mongo"
2 years ago
"gopkg.in/mgo.v2/bson"
2 years ago
"time"
2 years ago
)
2 years ago
var (
Client *mongo.Client
)
2 years ago
func GetUserAllChat(uid string) {
2 years ago
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
2 years ago
collection := Client.Database(config.Config.Mongo.DBDatabase).Collection("msg")
2 years ago
var userChatList []db.UserChat
2 years ago
uid = uid + ":"
2 years ago
filter := bson.M{"uid": bson.M{"$regex": uid}}
//filter := bson.M{"uid": "17726378428:0"}
2 years ago
result, err := collection.Find(context.Background(), filter)
2 years ago
if err != nil {
2 years ago
fmt.Println("find error", err.Error())
2 years ago
return
}
2 years ago
if err := result.All(ctx, &userChatList); err != nil {
2 years ago
fmt.Println(err.Error())
}
for _, userChat := range userChatList {
for _, msg := range userChat.Msg {
msgData := &server_api_params.MsgData{}
err := proto.Unmarshal(msg.Msg, msgData)
if err != nil {
fmt.Println(err.Error(), msg)
continue
}
2 years ago
fmt.Println("seq: ", msgData.Seq, "status: ", msgData.Status, "sendID: ", msgData.SendID, "recvID: ", msgData.RecvID, "sendTime: ", msgData.SendTime)
2 years ago
}
}
}