What have I learned about databases? The first database that I touched was MongoDB. It’s a NoSQL database, and apparently it’s easier to deal with than SQL or relational type databases. I can’t say if that’s the case yet, but I have started a course on MySQL so will know soon.
I read that SQL/Relational databases came first. They were invented at IBM. Everything is organized into neat rows and columns like a spreadsheet. NoSQL databases were created in response to the massive amounts of data that was being generated by the internet, that was often not easy to organize into tables; it was unstructured.
MongoDB is more flexible than MySQL with how you store data, but I think it’s more common that people try to use tools like mongoose to give their data some structure. I used MongoDB with Node.js, Express, and Mongoose. Using mongoose you can create a schema which is basically a model for how a piece of data should look. For example if you have a collection of apples you can give them different attributes such as color or flavor. So for example
[
{
‘name’:’Red Delicious’,
‘color’: ‘red’,
‘flavor’: ‘sweet’
},
{
‘name’: ‘Granny Smith’,
‘color’: ‘green’,
‘flavor’: ‘tart’
}
]
You’re probably thinking,” That looks like an array of objects.” ‘Cuz that’s exactly what I was thinking too. Apparently an array of objects is considered the best way to store data in MongoDB.
If you try to add attributes that don’t fit the schema it will get dropped. It won’t be added. Which is something I haven’t had to worry about. I think that may be something that you have to take into consideration when others are using your database.
Then you can add this array of objects into mongoDB using a function like so:

But let me backup because you first have to create the schema with mongoose.
Which looks like this:

Remember to require it in your routes like so:
const Card = require(‘ path/to/models’)
Something interesting is that I’m using mongoDB atlas. My localhost website can modify it and my deployed website will have access to it. I can just run a function on my localhost to add a collection and comment it out before deploying it. I made the mistake of deploying before commenting out that function and ended up with many copies of my collection, but it was easy to just delete it all from the mongoDB website.
As you may have guessed this is a piece of a flashcard app that I created for learning drug names. You can try it here: www.pharmacyrizz.com/flashcards
A long term goal is to enable users to create their own decks.
You may be wondering if I typed out all the cards by hand. I did not. I used Python and I will talk about that in a future post. Stay tuned.
