Should I go with MySQL or MongoDB? [closed] - mysql

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm in the planing phase of the development of an mobile app and I need your help to decide wheather I should go with MySQL or MongoDB. First let me describe the data:
I have a set of Items (e.g. movies) that users will be able to browse and score in different ways. The total number of Items is approximately 20 000 and it will not grow or shrink.
Each user will be able to score each item (numerical value) and write a comment assigned to each item. I expect that the average user will score maybe 40 different items, but my hopes are higher!
The typcial queries will be
Give me all items that satisfies some criteria and let me browse them. Example: Give me all Thrillers produced in Europe during the 00s.
Give me all movies that a particular user has scored.
I would also like to do some server side calculations e.g. average score for each movie, and each time a user sumbits a new score for an item this average should be updated.
For MySQL I would have a database with 3 different tables for this (Items, Users, Scores) and for MongoDB I'm considering a database with 1 collection, like this:
{
"name":"Inception"
"year":2010
"director":"Christopher Nolan"
"scores" : [
{
"user_id": 1234
"scoreA" : 3,
"scoreB" : 5,
"scoreC" : 4,
},
{
"user_id": 1235
"scoreA" : 4,
"scoreB" : 3
},
}
{
"name":"Titanic"
"year":1997
"director":"James Cameron"
"scores" : [
{
"user_id": 1201
"scoreB" : 5,
"scoreC" : 5
},
{
"user_id": 1220
"scoreA" : 4,
"scoreC" : 5
},
}
...
Question: Given my use case, does it matter if I use MySQL or MongoDB?
Thank you in advance!

Go with a relational database like mysql, there is no need to use MongoDb here unless you just wanna try it out.
As generell advice use NoSQL (especially MongoDb) when you can't improve your RDMS anymore.
Also take a look at this wonderful presentation: http://www.thedotpost.com/2015/06/neha-narula-consistency-and-candy-crush

Related

Should I normalise my database in this case? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
I got stuck with one problem in my website's database. I hope that I explained it well enough below:
My website's idea is to show prices in different shops for the same product. For example I have product "shoesA" it is sold in shopA, shopB, and shopC.
The prices for shoesA are as follows:
shopA : 107$,
shopB : 114$,
shopC : 97$
I can see 2 major ways of storing data about the product:
1) Store ALL the data regarding a single product in a single table, in a single row. This will require using 2D arrays.
Example:
ID=48,
Name="shoesA",
Brand="brandA",
Prices="[["shopA" , 107] , [["shopB " , 114] , [["shopC " , 97]]",
2) Divide this all into separate tables.
Example:
table_product_info
ID=48,
Name="shoesA",
Brand="brandA"
table_product_prices_shopA
ID=4,
Product_ID=48,
Price=107
table_product_prices_shopB:
ID=4,
Product_ID=48,
Price=114
table_product_prices_shopC
ID=4,
Product_ID=48,
Price=97
Why do I think that 1 is faster, hence, better than 2:
To get the entire data for shoesA using method 1 I only need to perform 1 query. But for method 2 it will possibly be 10 queries.
Thank you very much if you spent your time reading this and trying to help!
both are not quite right.
you want the product table to list the product details.
then you want the store table to list the store details.
then finally you need one to tell which product is sold by which store something like this:
store_product
______________
store_id
product_id
begin_date
end_date
price

How to show an image that a user has uploaded [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to show an image that a user has uploaded as part of a recipe but keep getting an error:
Illuminate\Database\QueryException SQLSTATE[HY000]: General error: 1
table recipes has no column named amount (SQL: insert into "recipes"
("image", "title", "servings", "ingredients", "amount",
"instructions", "user_id", "updated_at", "created_at") values
(uploads/U7lIutRFmbpyDz6EOUaExPGh5nYHElXZHcJv56CT.jpeg, pasta recipe,
4, pasta, 50g, cook it, 9, 2020-03-04 12:23:16, 2020-03-04 12:23:16))
It stores the image ok but nothing else.
Not sure on how to get the other fields to store either.
Below is the controller for recipes
enter image description here
Any help is much appreciated!
When it come to migrations, there's a general rule you should follow: Don't modify migrations after they have been run, unless you have the specific intent of re-running that migration. Generally, this requires a refresh of your database, and truncation of data.
You should make a new migration, like add_amount_to_recipies.php, which has the sole purpose of adding this new column in public function up(), and removing it in public function down():
public function up(){
Schema::table('recipies', function($table) {
$table->string('amount');
});
}
public function down(){
Schema::table('recipies', function($table) {
$table->dropColumn('amount');
});
}
Then, run php artisan migrate. This will add the column to the table without modifying the existing data.

/Download JSON and only update if there is a change. Can Firebase do this? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I plan on having a massive JSON, ~20MB, and I am creating a React Native App using the JSON. I want to have the app:
Download only the changes to the JSON.
or at least
Download only if changes have been made (which will be less than once a month).
If there is something better than Firebase I would be fine switching over to that.
I had the same issue, a huge JSON object which change once a week. the way that I solved this issue is as following
lets say that we have an object O ~20MB
I created in my firebase db the object data = {raw: O, update: Date()}
on the client side I checked /data/update and compare it to the user localStorage. if it changed I replaced the user`s localstorage object, otherwise skipped.
In this way you dont need to download the whole O only to fetch the date object
it looks like
const {update, raw} = localStorage.fetch('/data')
const last_update = firebase.fetch('/data/update')
if(update === last_update){return raw}
const new_raw = firebase.fetch('/data/raw')
localStorage.save('/data', {update: last_update, raw: new_raw})
return new_raw

how to structure the data in tables format? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have the following data in .dat format which i opened in excel and it turns out this way
1::Toy Story (1995)::Animation|Children's|Comedy
2::Jumanji (1995)::Adventure|Children's|Fantasy
3::Grumpier Old Men (1995)::Comedy|Romance
4::Waiting to Exhale (1995)::Comedy|Drama
5::Father of the Bride Part II (1995)::Comedy
6::Heat (1995)::Action|Crime|Thriller
7::Sabrina (1995)::Comedy|Romance
I want to structure it in table format like below..
Movie ID Movie Name Year of Release MovieType1 MovieType 2 MovieType 3
1 Toy Story 1995 Animation Children's Comedy
2 Jumanji 1995 Adventure Children's Fantasy
3 Grumpier Old Men 1995 Comedy Romance
and so on..
should i use R for it..or is it possible in excel itself ?
To import the data into an Excel spreadsheet, please try these instructions...
Start Excel.
Choose File --> Open.
Choose Browse...
Change the File Type to "All Files (.)".
Navigate to and select your .dat file.
Choose the Open button.
Choose the delimited option if it has not defaulted to that.
Set the "Start import at row" to the number of the row where your
data starts.
Choose "My data has headers" if appropriate.
Choose "Next".
Unselect any value in the Delimiters collection bar "Other".
Select "Other" if it is not already selected.
Enter a colon into the textbox next to "Other"
Select "Treat consecutive delimiters as one" if not already
selected.
Choose "Next".
Set the column data formats as appropriate.
Choose "Finish".
If you have any questions or comments, then please feel free to post a Comment accordingly.

R Studio Viewer issue [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am running the folliwing code:
trial = read.csv("trial.csv",
header = TRUE,
sep = ",",
na.string = "NA",
skip = 0,
strip.white = TRUE,
stringsAsFactors=FALSE
)
which I've successfully run for 3 previous datasets. No problem, I eventually merged them and did my stuff.
However, on this one I can't understand what's going on: the dataset doesn't open. I've tried to see which column was giving me the problem and it is the sixth
x<-trial[6]
which is the only numeric one. So i thought it was a conversion problem (the string one, even if I put the code in the import one.
But it is not this problem, since when I run
str(trial)
it gives me num, as it should.
It's been a week I've been trying to solve this apparently simple problem but I can't pull though.
EDIT2 The IMF dataset I0m using can be freely downloaded at this link. You need to register (free) to do the bulk download at the top right. I'm not sure if this is the right way to link a dataset, pls let me know.
When you download the dataset, just choose one country (e.g. Italy) and leave the option "all indicators".
EDIT. There is no shown error message.