# Document Db

## Description

Document stores register through `IFlexDocumentStore<TDocument>` (and `IFlexDocumentStore` for multi-collection scenarios). Your application code stays provider-agnostic while Cosmos DB, DynamoDB, MongoDB, and RavenDB handle persistence.

## Configuration in DI

Register only the provider store(s) you need.

```csharp
// Pick ONE provider and register the document types you use.
services.AddFlexCosmosDocumentStore<CustomerProfile>(configuration);
// services.AddFlexMongoDocumentStore<CustomerProfile>(configuration);
// services.AddFlexDynamoDocumentStore<CustomerProfile>(configuration);
// services.AddFlexRavenDocumentStore<CustomerProfile>(configuration);
```

## appsettings.json

Document DB configuration is read from `FlexBase:DataStores:Document:<Provider>`.

```json
{
  "FlexBase": {
    "DataStores": {
      "Document": {
        "CosmosDb": {
          "Endpoint": "https://...",
          "AccountKey": "<store-in-secrets>",
          "DatabaseName": "{YourApplication}",
          "ContainerName": "CustomerProfiles"
        }
      }
    }
  }
}
```

## Sample usage ({YourApplication})

```csharp
public class CustomerOnboarding
{
	private readonly IFlexDocumentStore<CustomerProfile> _customerProfiles;

	public CustomerOnboarding(IFlexDocumentStore<CustomerProfile> customerProfiles)
		=> _customerProfiles = customerProfiles;

	public async Task MarkSeenAsync(string id)
	{
		var profile = await _customerProfiles.GetAsync(id);
		if (profile is null) return;

		profile.LastSeen = DateTime.UtcNow;
		await _customerProfiles.UpsertAsync(profile);
	}
}
```

## Provider pages

* Cosmos DB: `document-db/cosmos-db.md`
* DynamoDB: `document-db/dynamo-db.md`
* MongoDB: `document-db/mongo-db.md`
* RavenDB: `document-db/raven-db.md`

## Provider considerations

* Keep secrets (keys/connection strings) out of source control.
* For Cosmos DB, set partition keys consistently with your model and access patterns.
