# WithTlsMode

- Module: [Aspire.Hosting.MongoDB](/reference/api/go/aspire.hosting.mongodb.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: [`MongoDBServerResource`](/reference/api/go/aspire.hosting.mongodb/mongodbserverresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

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
func (MongoDBServerResource) 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()`.

## Applies to

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