sun-pc-linux 7 months ago
parent
commit
79fd80a43f
1 changed files with 3 additions and 3 deletions
  1. 3 3
      boxcost/db/repo/repo.go

+ 3 - 3
boxcost/db/repo/repo.go

@@ -100,9 +100,9 @@ func RepoAddDoc1(ctx *RepoSession, collectName string, doc interface{}, recordLo
 	if err != nil {
 		return "", err
 	}
-	insertId, err := result.InsertedID.(primitive.ObjectID).Hex(), nil
-	if len(insertId) > 0 {
-		_id, _ := primitive.ObjectIDFromHex(insertId)
+	_id := result.InsertedID.(primitive.ObjectID)
+	insertId, err := _id.Hex(), nil
+	if !_id.IsZero() {
 		if isShouldRecordHistoryByName(collectName) {
 			var newData Map
 			colls.FindOne(ctx.Ctx, bson.M{"_id": _id}).Decode(&newData)