@Override
    protected void update(final String username, final Collection<CredentialRegistration> givenRecords) {
        val records = givenRecords
            .stream()
            .map(record -> {
                if (record.getRegistrationTime() == null) {
                    return record.withRegistrationTime(Instant.now(Clock.systemUTC()));
                }
                return record;
            })
            .collect(Collectors.toList());

        val query = new Query(Criteria.where(MongoDbWebAuthnCredentialRegistration.FIELD_USERNAME).is(username))
            .collation(Collation.of(Locale.ENGLISH).strength(Collation.ComparisonLevel.primary()));
        val collection = getProperties().getAuthn().getMfa().getWebAuthn().getMongo().getCollection();
        if (records.isEmpty()) {
            LOGGER.debug("No records are provided for [{}] so entry will be removed", username);
            mongoTemplate.remove(query, MongoDbWebAuthnCredentialRegistration.class, collection);
        } else {
            val jsonRecords = FunctionUtils.doUnchecked(() -> getCipherExecutor().encode(WebAuthnUtils.getObjectMapper().writeValueAsString(records)));
            val entry = MongoDbWebAuthnCredentialRegistration.builder()
                .records(jsonRecords)
                .username(username)
                .build();

            val update = Update.update(MongoDbWebAuthnCredentialRegistration.FIELD_RECORDS, jsonRecords);
            val result = mongoTemplate.updateFirst(query, update, collection);
            if (result.getMatchedCount() <= 0) {
                LOGGER.debug("Storing new registration record for [{}]", username);
                mongoTemplate.save(entry, collection);
            }
        }
    }
This is {@link MongoDbWebAuthnCredentialRepository}.

@author Misagh Moayyed
@since 6.3.0
support/cas-server-support-webauthn-mongo/src/main/java/org/apereo/cas/webauthn/MongoDbWebAuthnCredentialRepository.java