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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flexbase.in/data-and-providers/data-stores/document-db.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
