How to push document if exists else insert other document

      insertDoc = %{
      "groupId" => groupObjectId,
      "userId" => userObjectId,
      "isActive" => true,
      "month" => dateTimeMap["month"],
      "year" => dateTimeMap["year"],
      "attendanceStaff" =>[%{
        "attendance" => status,
        "attendanceAt" => dateObject,
        "date" =>  "#{ String.slice("0"<>""<>to_string(dateTimeMap["day"]), -2, 2)}-#{String.slice("0"<>""<>to_string(dateTimeMap["month"]), -2, 2)}-#{dateTimeMap["year"]}",
        "dateString" => "#{dateTimeMap["year"]}#{String.slice("0"<>""<>to_string(dateTimeMap["month"]), -2, 2)}#{ String.slice("0"<>""<>to_string(dateTimeMap["day"]), -2, 2)}",
        "attendanceTakenById" => loginUserObjectId,
        "attendanceTakenByName" => loginUserName,
        "time" => indiaTime
      }]
    }
    updateDoc = %{
        "attendance" => status,
        "attendanceAt" => dateObject,
        "date" =>  "#{ String.slice("0"<>""<>to_string(dateTimeMap["day"]), -2, 2)}-#{String.slice("0"<>""<>to_string(dateTimeMap["month"]), -2, 2)}-#{dateTimeMap["year"]}",
        "dateString" => "#{dateTimeMap["year"]}#{String.slice("0"<>""<>to_string(dateTimeMap["month"]), -2, 2)}#{ String.slice("0"<>""<>to_string(dateTimeMap["day"]), -2, 2)}",
        "attendanceTakenById" => loginUserObjectId,
        "attendanceTakenByName" => loginUserName,
        "time" => indiaTime
    }
    StaffAttendanceRepo.applyAttendance(userObjectId, dateTimeMap["month"], insertDoc, update) '''


mongo query
filter = %{
    "userId" => userObjectId,
    "month" => month,
   }
   update = %{
   "$setOnInsert" => insertDoc,
   "$push" =>   %{"attendanceStaff" => updateDoc}
   }
   project = %{
     "upsert" => true,
   }
  Mongo.update_one(@conn, @staff_attendance_db, filter, update, [projection: project])


output
# {:error, %Mongo.Error{code: 40, message: "Updating the path 'attendanceStaff' would create a conflict at 'attendanceStaff'"}}


any other way to achieve it