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

更新单元格值时应该判断匹配的条数,而不是修改的条数 #3

Open
yjq635 opened this issue Apr 1, 2021 · 0 comments

Comments

@yjq635
Copy link

yjq635 commented Apr 1, 2021

func (d *dao) UpdateGridValue(ctx context.Context, gridKey string, req *model.UpdateV) (err error) { c := d.mongo.Database(dbname).Collection(gridKey) filter := bson.M{"index": req.I, "celldata": bson.M{"$elemMatch": bson.M{"r": req.R, "c": req.C}}} formatV, err := d.format2Bson(req.V) if err != nil { log.With("err", err).With("v", req.V).Errorln("format2bson error") return } res, err := c.UpdateOne(ctx, filter, bson.D{{"$set", bson.D{{"celldata.$.v", formatV}}}}) if err != nil { log.With("err", err).With("gridKey", gridKey).With("req", req).Errorln("update error") return } if res.ModifiedCount <= 0 { formatCell, err := d.format2Bson(req.Cell) if err != nil { log.With("err", err).With("cell", req.Cell).Errorln("format2bson error") return err } _, err = c.UpdateOne(ctx, bson.M{"index": req.I}, bson.M{"$push": bson.M{"celldata": formatCell}}) } return err }
mongo.go:第171行这个地方 应该以匹配行数是否大于0来判断该sheet是否有这个单元格
现有的逻辑在批量设置格式时(rv操作)部分v值完全没有变化时,res.ModifiedCount就是0了,但matchedCount是1,
这个时候按现有代码逻辑 就会push一条新的数据到celldata中,最终导致celldata中同一个单元格有两个值

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant