Skip to content

Commit ed2a583

Browse files
author
Bart Koelman
committed
Updated documentation
1 parent 8ce524d commit ed2a583

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dotnet add package JsonApiDotNetCore.MongoDb
1818
#nullable enable
1919

2020
[Resource]
21-
public class Book : MongoIdentifiable
21+
public class Book : HexStringMongoIdentifiable
2222
{
2323
[Attr]
2424
public string Name { get; set; } = null!;
@@ -70,9 +70,19 @@ builder.Services.AddJsonApiMongoDb();
7070
builder.Services.AddScoped(typeof(IResourceReadRepository<,>), typeof(MongoRepository<,>));
7171
builder.Services.AddScoped(typeof(IResourceWriteRepository<,>), typeof(MongoRepository<,>));
7272
builder.Services.AddScoped(typeof(IResourceRepository<,>), typeof(MongoRepository<,>));
73-
7473
```
7574

75+
## Using client-generated IDs
76+
Resources that inherit from `HexStringMongoIdentifiable` use auto-generated (performant) 12-byte hexadecimal
77+
[Object IDs](https://docs.mongodb.com/manual/reference/bson-types/#objectid).
78+
You can assign an ID manually, but it must match the 12-byte hexadecimal pattern.
79+
80+
To assign free-format string IDs manually, make your resources inherit from `FreeStringMongoIdentifiable` instead.
81+
When creating a resource without assigning an ID, a 12-byte hexadecimal ID will be auto-generated.
82+
83+
Set `options.AllowClientGeneratedIds` to `true` in Program.cs to allow API clients to assign IDs. This can be combined
84+
with both base classes, but `FreeStringMongoIdentifiable` probably makes the most sense.
85+
7686
## Limitations
7787

7888
- JSON:API relationships are currently not supported. You can use complex object graphs though, which are stored in a single document.

0 commit comments

Comments
 (0)