@@ -18,7 +18,7 @@ dotnet add package JsonApiDotNetCore.MongoDb
18
18
#nullable enable
19
19
20
20
[Resource ]
21
- public class Book : MongoIdentifiable
21
+ public class Book : HexStringMongoIdentifiable
22
22
{
23
23
[Attr ]
24
24
public string Name { get ; set ; } = null ! ;
@@ -70,9 +70,19 @@ builder.Services.AddJsonApiMongoDb();
70
70
builder .Services .AddScoped (typeof (IResourceReadRepository <,>), typeof (MongoRepository <,>));
71
71
builder .Services .AddScoped (typeof (IResourceWriteRepository <,>), typeof (MongoRepository <,>));
72
72
builder .Services .AddScoped (typeof (IResourceRepository <,>), typeof (MongoRepository <,>));
73
-
74
73
```
75
74
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
+
76
86
## Limitations
77
87
78
88
- JSON: API relationships are currently not supported. You can use complex object graphs though, which are stored in a single document.
0 commit comments