# withKeyFile

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

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)
