I’d like to get some guidance (reference books and sites) to help “unlearn” the relational db constraints while having great performance on NoSQL.
I’ll introduce my current issue:
I have several products and several users, there’s a N-to-M relationship between those entities.
Easily I could move it to NoSQL having a users bucket with this contents:
// user
{
id: "user::35c8a035-ee7e-48b8-b81b-6752ab642120",
name: "enwine"
products: [
"product::a251ca83-c95c-491a-be11-00d5605e75a4",
"product::3773a25a-5452-4891-ada0-bb7bb1747bc9",
],
...
}
And another bucket with Products like:
// product
{
id: "product::a251ca83-c95c-491a-be11-00d5605e75a4",
name: "VIP User"
price: "$20/mo"
}
The point is that I want to be able to:
- List all users (including more fields than just the id) that own a given product. I figured out this solution for that: Create a view that from the Users bucket that returns all users for a given product id.
- List all products (including more fields than just the id) owned by a given user. This is more complex, as it is just
user.products
, but to display the list with more info, I’ll have to fetch all of the products of the list, one by one. - Being able to automatically remove one product from all users using it on demand: I mean, if one product (let’s say “VIP Membership”) gets removed, users can no longer own it, and therefore, the only way I can figure out to do it, is updating users document one by one, which is not admisible.
Could anyone please enlighten me?
Thanks,
~enwine