datamodeling with cassandram nosql - nosql

Im trying to make a datamodel for a little game im making but i have no experience with nosql database models yet.
here is the idea:
there is a village, the village belongs to a user, and a user can have multiple villages. a village cannot have multiple owners.
any suggetions/links on a good way to work this out?
Thanks

User
[Village ...]
From what you have said, a simple composite structure with an array of villages in user will work.

Related

Database related to users

I am trying to build a full stack application that can remember specific properties when users are logged in. I want to incorporate a database(mongoDB). When the users are logged in, I want the users to be able to add their favourite food items.
As for how I would develop something like this, I am a little bit confused on the back end of things. I just want to make sure my method is appropriate before I start writing code.
As of right now, I am able to add new users to my database, but to remember what a specific users favorite food is, would I just modify the existing database for that specific user?
For example, if I had user A and B and if I add new food to User A, would I just add new food items to the key-value pair associated with user A? Would there be a better way to do this? If it helps, I will also be using node and express. I did read online that I could use cookie session in express, but I want to get familiar with databases.
Thanks!
Your method seems like it would work, but it's hard to say without knowing the full use of the "favorite food" feature. If you're just trying to have some text in the user's profile that says "Favorite Food: Pizza and stuff" then your approach is simple and it works. Don't use cookies/sessions if you want to store this information permanently. If you're trying to match users to other people with the same favorite foods or you have a preset list of foods the users must choose from, then you might want to consider other database schema.
I'm not too familiar with MongoDB, but I do know they pride themselves on being ~different~
Check out this article from MongoDB, as it seems to explain some different database approaches and MongoDB features and their pros and cons.
Good luck!

Organizing MongoDB database containing different account types

I am working on a react-native app using nodejs and mongodb on the backend. In my app users are able to create multiple accounts and there are different account types (Business, Artist, Venue, etc.). For the most part, each account type has the same data and fields in the database. Things like name, location, website. But it is possible for each account type to have a couple pieces of data specific to that account. My question is, should I simply have one "Account" collection in the database that stores all accounts and has an "accountType" field to differentiate each account?
Initially I thought to do the opposite and store each account type in a separate collection, but I found it made the client code pretty messy as I found myself adding a bunch of if statements to determine things like what api endpoint to make requests to, what components to render, and what screens to navigate to, when in reality, it's really just a couple pieces of data that may change from one account type to another.
It seems like having just one "Accounts" collection with an "accountType" field will greatly simplify the code. But maybe there is something I am missing. If anyone has some insight as to which approach may be better for the situation, or some of the pros/cons of each approach, I'd really appreciate the help! Thanks!
Well, the answer clearly depends on how the documents for different types of accounts differ. But, the idea of going with a single collection is fine, also take a look at the Subset Pattern, it's will give you a fine idea, of how to divide data into different collections, depending on their usage.

Dilemma with the data model using MongoDB

I am working on an application on which we'll have users and videos.
It's a n-n relationship, a user can be related to several videos, and the same video can be related to several users.
I decided to go with mongoDB on the implementation, though I wasn't familiar with this technology at first, so I run into a problem regarding the document data model (in contraposition with the entity-relation data model).
In this application I'll need to access frequently the videos that are somehow related to a certain user. From this point of view, it would be logical to embed the document 'video' in the document 'user'.
But, I will also need frequent access to video collections, regardless of the users related to them. From this point of view, it seems the data model would be better designed if the the users related to the video were embedded inside its document.
Both designs make sense, and solve a problem, but make the remaining problem quite hard to solve; I would have to perform complex, inefficient queries to actually be able to get both functionalities with any of those two designs.
Right now I think the best decission would be to implement it the same way I would in a relational database (with two different documents for users and videos, and an intermediate document that allows me to know the relations between those two).
I'm really not sure that is the way this problem should be solved in mongoDB, so I would like to ask for advice regarding the data model design.
Thanks in advance.
Do both.
While redundancy should be avoided in a relational database, the same is not true for a document-oriented database. When you have no JOINs, you need to make sure that every common query can be fulfilled with documents from a single collection. Redundancy is usually the only way to achieve this.
The downside is that you now need two queries to update the relation, because both the video and the user document need to be updated. But that's a small price to pay, especially considering that updates are usually not as performance-critical as reads (you can perform them in the background while faking the result on the frontend for the user who requested the update).

Best practice for dealing with different groups of users in mongodb

I have 2 groups of users on my website. One is user and the other one is admin. Currently I put them in 2 different collections user and admin. My questions is:
Mongodb generates _id automatically for both collections. Since they're in 2 different collections chances are one day you created one user and one admin with the same _id right? I have a table keeping track of user / admin balances so I certainly don't want the _id to collide.
I can also put all users and admins in one collection. This way I don't have a problem but I am not sure if I should do this.
Any comments are greatly appreciated. Thanks!!
There is a very very low chance that you will have collisions.
Yes, you could put users and admins in one collection and then have a 'type' attribute that differentiates regular users and admin users. I don't know your requirements or why you have them in separate collections currently, so I can't say if you should or shouldn't do it, but it sounds like it would make some things easier.

MongoDB permissions-based modelling problem

I'm trying to model a simple, experimental app as I learn Symfony and Doctrine.
My data model requires some flexibility, so I'm currenty looking into the possibility of using either an EAV model, or document store in MongoDB.
Here's my basic requirements:
Users will be able to store and share their favourite things (TV prog, website, song etc).
The list of possible 'things' a user can store is unknown. For example, a user may want to store their favourite animal.
Users can share their favourite things with other users. However, a user can decide what he / she shares with each other user. For example, a user may share their favourite movie with one user, but not another.
A typical user will log in and view all the favourite things from their list of friends, depending on what his friends have decided to share. The user will also update their own favourite things, which will be reflected when each other users views their own profile. Finally, the user may change which of his friends can see what of his favourite thing.
I've worked a lot with Magento, which uses the EAV model extensively. However, I'm adding another layer of complexity by restricting which users can see what information.
I'm instantly drawn to MongoDB as the schemaless format gives me the flexibility I require. However, I'm not sure how easy (or efficient) it will be to access the data once it's saved. I'm also concerned about how changes to the data will be managed, e.g. a user changes their favourite film.
I'm hoping someone can point me in the right direction. This is purely a demo app I'm building to further my knowledge, but I'm treating it like a real-world app where data access times are super-important.
Modelling this kind of app in a traditional relational DB makes me sweat when I think about the crazy number of joins I'd need to get the data for one user.
Thanks for reading this far, and please let me know if I can provide anymore information.
Regards,
Fish
You need to choose a model based on how you need to access the data.
If you just need to filter out some values when viewing the user profile, a single document for each user would work quite well, with each favorite within that having a list of authorized user/group IDs that is applied in the application code. Both read and write are single operations on a known document in this case, so will be fast.
If you need views across multiple profiles though, your main document should probably be the favorite. You'll need to set up the right indexes, but performance shouldn't be a problem.
Actually, the permissions you describe don't add that much complexity to an EAV schema - as long as attributes can have multiple values the permissions list is just one more attribute.