[20:45:49] <Zta77> GothAlice: thanks for the document https://www.javaworld.com/article/2088406/how-to-screw-up-your-mongodb-schema-design.html -- It's old but still valid.
[20:48:34] <GothAlice> Identifying documents is key. :)
[20:50:33] <Zta77> At first I thought I could make a dirty short cut and use the same model class that I got from the web service in my business logic and store in my db. I quickly found out that the web service and my own service needed separate models.
[20:50:33] <Zta77> No problem, I use a mapper (Dozer) to translate between the two. I still hoped I could use my own business model for persisting into mongo. But then I discovered _id.
[20:51:35] <GothAlice> You can get away with some neat stuff if you grok MongoDB document structuring, and the use of expressive atomic operations. Like, implement a 1.9 million distributed RPC call-per-second task queue. Atomic record locking. O(1) lookups for things like rendering an entire page of forum thread replies—all data needed for the whole page (other than auth-related, possibly). Use of V2 ObjectIds to allow differentiation of records
[20:51:35] <GothAlice> constructed on different application workers (logging…), etc.
[20:52:32] <Zta77> Looks like I need an (e.g.) AnimalResponse, Animal, and AnimalDocument after all. Who would have guessed...three-tier and all.
[20:53:05] <GothAlice> It does happen, and MongoDB does have LEFT OUTER joins.
[21:01:18] <Zta77> I did add a PojoCodec so everything works most of the time, but I might as well make use of indexes from the beginning. This object of mine has a 'date' that is basically a unique id. What's the best way to map between Animal (domain model that has 'date' but no id) and AnimalDocument (where '_id' should be equivalent to 'date')?
[21:04:29] <Zta77> I could simply ( AnimalDocument.from(animal) ) and do the mapping of all fields including the date-to-id manually but I don't like manually.
[21:08:16] <Zta77> And 2: How do I get Instant serialized/deserialized more efficiently? Apparently there's an InstantCode, but I haven't found a way to add it yet.
[21:22:00] <Zta77> Oh shoot, I'd really prefer not to make entity/document models, but instead be able to store my actual domain models. But again, have an _id added automatically.
[21:45:51] <Zta77> (Ah, updating to a recent java driver fixed the Instant serialization).
[22:09:02] <Zta77> It would be nice if I could give an extra option to collections.insertOne(doc, () -> doc.date.toString()) that would generate the id on the fly upon insert.