You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Customise MongoDB persistence options and _id generation
92
+
93
+
In addition to `MongoDbIdentifiable` your resource classes are free to use any of the MongoDB driver persistence options or inherit from their own base class.
94
+
95
+
For example, you could change the example above so that the `Book` resource has string IDs rather than object ids in the DB, but still have them generated server side:
96
+
97
+
```cs
98
+
publicclassBook : IIdentifiable<string>
99
+
{
100
+
// If Id=null generate a random string ID using the MongoDB driver
Resources just need to inherit from the base `IIdentifiable<string>` interface from JsonApiDotNetCore (or the provided default `MongoDbIdentifiable`) and then just use any of usual [MongoDB Driver mapping code](https://mongodb.github.io/mongo-csharp-driver/2.12/reference/bson/mapping/).
117
+
118
+
You could also achieve the exact same result using MongoDB `BsonClassMap`[rather than attributes](https://mongodb.github.io/mongo-csharp-driver/2.11/reference/bson/mapping/) so your `Book` does not need any MongoDB specific code like below.
Using `StringObjectIdGenerator` above could then be combined with `AllowClientGeneratedIds` JsonApi setting in `Startup.ConfigureServices` so that IDs can be generated on the client, and will be auto-assigned server side if not provided providing a flexible string based id for the `Book` resource:
131
+
132
+
```cs
133
+
services.AddJsonApi(options=> {
134
+
// Allow us to POST books with already assigned IDs!
0 commit comments