# MongoDBServerResource.WithReplicaSet

- 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 and initializes the MongoDB server as a single-member replica set for local development.

## Remarks

Enables transactions and change streams without changing database resources or references. The server becomes
healthy only after initialization and primary election. Connections use the server's normal endpoint directly;
a developer certificate, topology discovery, and fixed host ports are not required.
A key file is generated for authentication unless `WithKeyFile` was called first.
Existing single-member data is reused without reconfiguration. Keep the set name and credentials unchanged when
reusing a data volume. Publishing and deploying this configuration are not supported.
Unlike the previous low-level behavior of this experimental method, this method initializes the set.
For multiple members, use `AddMongoDBReplicaSet` and
`WithMember` instead, without calling this method on the members.

## Definition

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

## Signature

```go
WithReplicaSet(options ...*WithReplicaSetOptions) MongoDBServerResource
```

## Parameters

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

## Options

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

- `Name` (`*string`) -- The replica set name. Defaults to the resource name, or the name previously configured by this method.

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