Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] mongodb transaction failed: mongo find one and update: Failed to parse update: field must be of BSON type object: Failed to parse update: field must be of BSON type object"} #2892

Open
hejianbing opened this issue Nov 26, 2024 · 1 comment
Labels
bug Categorizes issue or PR as related to a bug.

Comments

@hejianbing
Copy link

hejianbing commented Nov 26, 2024

OpenIM Server Version

v3.8.2

Operating System and CPU Architecture

Linux (AMD)

Deployment Method

Source Code Deployment

Bug Description and Steps to Reproduce

func (l *VersionLogMgo) writeLogBatch2(ctx context.Context, dId string, eIds []string, state int32, now time.Time) (*model.VersionLog, error) { if eIds == nil { eIds = []string{} } filter := bson.M{ "d_id": dId, } elems := make([]bson.M, 0, len(eIds)) for _, eId := range eIds { elems = append(elems, bson.M{ "e_id": eId, "version": "$version", "state": state, "last_update": now, }) } pipeline := []bson.M{ { "$addFields": bson.M{ "delete_e_ids": eIds, }, }, { "$set": bson.M{ "version": bson.M{"$add": []any{"$version", 1}}, "last_update": now, }, }, { "$set": bson.M{ "logs": bson.M{ "$filter": bson.M{ "input": "$logs", "as": "log", "cond": bson.M{ "$not": bson.M{ "$in": []any{"$$log.e_id", "$delete_e_ids"}, }, }, }, }, }, }, { "$set": bson.M{ "logs": bson.M{ "$concatArrays": []any{ "$logs", elems, }, }, }, }, { "$unset": "delete_e_ids", }, } projection := bson.M{ "logs": 0, } opt := options.FindOneAndUpdate().SetUpsert(false).SetReturnDocument(options.After).SetProjection(projection) res, err := mongoutil.FindOneAndUpdate[*model.VersionLog](ctx, l.coll, filter, pipeline, opt) if err != nil { return nil, err } res.Logs = make([]model.VersionLogElem, 0, len(eIds)) for _, id := range eIds { res.Logs = append(res.Logs, model.VersionLogElem{ EID: id, State: state, Version: res.Version, LastUpdate: res.LastUpdate, }) } return res, nil }
拼接BSON 格式错误

Screenshots Link

No response

@hejianbing hejianbing added the bug Categorizes issue or PR as related to a bug. label Nov 26, 2024
@skiffer-git
Copy link
Member

Under what circumstances does this issue occur?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants