Code Snippets

I have no idea if this is the best approach to a project but I'm implementing the MVC methodology to this web app that I'm building. As in, I'm first going to build as much of the model as I can then as much of the views as I can before working on the controller. As I mentioned yesterday, what I do know is that I will need two schemas for this project - one for the snippets and one for the users. I will be using a noSQL database because I already know how to use Mongoose to connect Mongo to my Node application.


One trick I knew I would have to add in order to 'link' the two collections in my database is on line 15. I knew I would have to give each snippet a way to connect to its owner in order to only display that owner's snippets. This probably would have been easier to do in a SQL database where tables have a bit more structure and can include foreign keys to reference other tables. However, I wanted to use tools I have already learned how to use to accomplish a bigger task.

I was also able to set my tags to a type of array in order to include multiple tags per snippet. The examples I was given in class looked a bit simpler than what I ended up using because I needed to require tags as well. At first, I used the syntax 'tags: [type: String, required: true]' but I wasn't confident that was correct. I Googled a bit and came to the conclusion that what I wrote wouldn't actually work at all so I promptly changed it to match the example provided in Mongoose's documentation.

Comments