开发者

How to store relational POCO's in nosql world?

开发者 https://www.devze.com 2023-01-31 14:04 出处:网络
We\' re working on a project that has a relational object model and we would like to use a no/sql solution (couchdb) for some part of data storage. For example, there are users and applications which

We' re working on a project that has a relational object model and we would like to use a no/sql solution (couchdb) for some part of data storage. For example, there are users and applications which are related to each other via Applications UserId field (Or User property in DDD world)

开发者_如何学Go

What is the right way to store "user" data in couchdb in an "Application" document? With id for relation or to put the entire "user" object in "application" document? If i put the entire "user" object in Application document, updating an user will cause to update all Application documents that has an entire user info inside it.

We' re little bit confused so i' ll be very happy to hear some ideas about that.

Thank you.


Either approach is valid, depending on what reads and writes you need - if the user object almost never changes, a slow/complex write process doesn't matter and you may be able to avoid a lot of extra reads by including it in the application document. If it changes a lot, the slow/complex writes become the dominant issue and it makes more sense to just put a reference in your application document. This is actually one of the bigger differences between SQL and NoSQL - SQL has one correct normalized structure, with NoSQL you need to think about your requirements more.

That said, user almost always makes sense as a standalone object. However, you aren't limited to using just the user id in your application document - including a display name (which rarely changes) probably eliminates almost as many reads as including the whole user object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号