# MongoDBServerResource.WithTlsMode

- Module: [Aspire.Hosting.MongoDB](/reference/api/go/aspire.hosting.mongodb.md)
- Defined on: [MongoDBServerResource](/reference/api/go/aspire.hosting.mongodb/mongodbserverresource.md)
- Version: `17.0.0`
- Kind: `method`

Configures the `--tlsMode` the MongoDB server is started with when TLS is active.

## Remarks

TLS itself is not turned on by this method. A MongoDB server resource serves TLS whenever an HTTPS/TLS certificate
is available for it -- by default the ASP.NET Core developer certificate -- and serves plain TCP otherwise. Use
`WithHttpsDeveloperCertificate` or
`WithHttpsCertificate` to opt in explicitly, and
`WithoutHttpsCertificate` to opt out. This method only controls
how strict the server is about TLS on incoming connections once TLS is active; the default is
`RequireTls`.
See https://www.mongodb.com/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.mode
Let clients connect either with or without TLS:
```
var mongo = builder.AddMongoDB("mongo")
.WithTlsMode(MongoDBTlsMode.PreferTls);
```

## Definition

```go
type MongoDBServerResource interface {
    // ... omitted for brevity
    WithTlsMode(options ...*WithTlsModeOptions) MongoDBServerResource
}
```

## Signature

```go
WithTlsMode(options ...*WithTlsModeOptions) MongoDBServerResource
```

## Parameters

- `options` (`...*WithTlsModeOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithTlsModeOptions` argument.

- `Mode` ([`*MongoDBTlsMode`](/reference/api/go/aspire.hosting.mongodb/mongodbtlsmode.md)) -- The TLS mode to run the MongoDB server in.

## Returns

[`MongoDBServerResource`](/reference/api/go/aspire.hosting.mongodb/mongodbserverresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Defined on

- [MongoDBServerResource](/reference/api/go/aspire.hosting.mongodb/mongodbserverresource.md) -- `handle`
