# withKeyFile

- Module: [Aspire.Hosting.MongoDB](/reference/api/typescript/aspire.hosting.mongodb.md)
- Version: `13.6.0`
- Kind: `method`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/f4c27f2d43ddc1cacd0dd083b30d1fea1cee7a62)

Sets up a keyfile for internal authentication between members of a MongoDB replica set, with the specified `keyValue` as the content of the file.

## Definition

```typescript
interface MongoDBServerResource {
  // ... omitted for brevity
  withKeyFile(
    keyValue: IExpressionValue,
    keyFilePath?: string): MongoDBServerResource
}
```

## Parameters

- `keyValue` (`IExpressionValue`)
- `keyFilePath` (`string`) `optional` `= /etc/rs.key`

## Returns

[MongoDBServerResource](/reference/api/typescript/aspire.hosting.mongodb/mongodbserverresource.md) `builder`

## Applies to

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