# MongoDBServerResource.withKeyFile

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

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;
}
```

## Signature

```typescript
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`

## Defined on

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