Status ServerSelectionMetadata::writeToMetadata(BSONObjBuilder* metadataBob) const {
    if (isSecondaryOk()) {
        metadataBob->append(kSecondaryOkFieldName, 1);
    }

    if (getReadPreference()) {
        metadataBob->append(kReadPreferenceFieldName, getReadPreference()->toBSON());
    }

    return Status::OK();
}
Status ServerSelectionMetadata::writeToMetadata(BSONObjBuilder* metadataBob) const {
    BSONObjBuilder ssmBob;
    if (isSecondaryOk()) {
        ssmBob.append(kSecondaryOkFieldName, 1);
    }

    if (getReadPreference()) {
        ssmBob.append(kReadPreferenceFieldName, getReadPreference()->toBSON());
    }

    auto ssm = ssmBob.done();
    if (!ssm.isEmpty()) {
        metadataBob->append(fieldName(), ssm);
    }

    return Status::OK();
}