This commit is contained in:
wangchuxiao
2023-05-11 15:30:06 +08:00
parent 89d5f7bd45
commit 351c5bacfa
2 changed files with 27 additions and 11 deletions
+23 -4
View File
@@ -137,12 +137,31 @@ func (m *MsgMongoDriver) UpdateOneDoc(ctx context.Context, msg *table.MsgDocMode
func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID string, beginSeq, endSeq int64) (msgs []*sdkws.MsgData, seqs []int64, err error) {
beginIndex := m.msg.GetMsgIndex(beginSeq)
num := endSeq - beginSeq + 1
result, err := m.MsgCollection.Find(ctx, bson.M{"doc_id": docID, "msgs": bson.M{"$slice": []int64{beginIndex, num}}})
if err != nil {
return nil, nil, err
pipeline := bson.A{
bson.M{
"$match": bson.M{"doc_id": docID},
},
bson.M{
"$project": bson.M{
"doc_id": 1,
"msgs": bson.M{
"$slice": []interface{}{"$msgs", beginIndex, num},
},
},
},
}
cursor, err := m.MsgCollection.Aggregate(ctx, pipeline)
if err != nil {
return nil, nil, errs.Wrap(err)
}
// result, err := m.MsgCollection.Find(ctx, bson.M{"doc_id": docID, "msgs": bson.M{"$slice": []int64{beginIndex, num}}})
// if err != nil {
// return nil, nil, err
// }
var msgInfos []table.MsgInfoModel
if err := result.Decode(&msgInfos); err != nil {
if err := cursor.All(ctx, &msgInfos); err != nil {
return nil, nil, err
}
if len(msgInfos) < 1 {