What exactly is the relationship between usersDao.js and users.controller.js?

What exactly is the relationship between usersDao.js and users.controller.js? The latter makes sense to me. The former is not so clear to me. And it all points back to adding a new user. I’m not so concerned about acing this course. I just want to learn this and learn properly. Thanks.

For the purpose of this course you don’t need to touch anything in the controller at all. You also don’t need to touch unit tests and the only place you need to make any edits are with the DAO section.

The relationship is that the implementation or “that part that actually does something” is ALL contained within the DAO. This is the logic center or “brain” of the application with regards to where all the parts go that actually do something with the database. The rest is really just scaffolding and conduits.

More to the point:

  • DAO - Does the actual work and contains the implementation parts that “do things”.
  • Controller - Depends on the DAO by accessing it’s methods and tying those to “actions”. Typically doing more specific HTTP server API things like “send this output as JSON”
  • Route - Is how in the design pattern used in this example has been applied separately to the controller to then define which routing points from the HTTP server actually correspond to each “action”

In all honesty if you “…want to learn this stuff properly…” then this is not really the most appropriate place to ask. Despite the course marketing, this is NOT a complete guide on how to engineer applications like this. The ONLY real focus here is the usage of MongoDB API with the NodeJS driver.

There are far better sources on the wider internet to learn application design patterns and principles from, so I would strongly suggest you instead look for that sort of information in the places it is more suitably presented.

I guess I am just used to setting up things differently with Express. Controller, route, no problem. Used to that there. The usersDao.js is just throwing me off because in my set up I wouldn’t have that page. If anything, I would have a mongoose model if I used it. I used have to have views, and now I am getting into the REST API and beyond. I just don’t get the concept of the set up as to how I am going to create a user based on the instructions. I understand the concepts in the video in theory, but it is not happening on attempt of implementation here. It feels like I am trying to create something from nothing.

1 Like

So the instructions as I have already mentioned are to “edit the DAO only

In a way each of th DAO files IS a “mongoose model”, just that you don’t really sound like you are used to implementing static and instance methods on that model, which is basically what the code you are being asked to write is.

More to the point:

  /**
  Ticket: User Management

  For this ticket, you will need to implement the following five methods:

  - getUser
  - addUser
  - loginUser
  - logoutUser
  - getUserSession

  You can find these methods below this comment. Make sure to read the comments
  in each method to better understand the implementation.

  The method deleteUser is already given to you.
  */

Those are the instructions and there are other threads for this. The only relation to this thread is this is the ONLY code you edit, so please do not attempt to change anything else.

The general scope of MVC design ( and variants ) is way to broad for discussion here, so there are better places as pointed out already.

Also please refrain from starting another thread on the same topic of “how to I pass the add a user lab”, since there are already responses on that. Noting mostly that “I can’t work it out” or “having problems” are not really descriptive anyway.

If you have problems passing the exercise and need help, then post specific details of errors and what you have done on existing threads instead of “please help” requests. People can give you pointers with specific problems, and there is already a list of quite detailed pointers in existing threads. I suggest you read those.

At the worst case if you were to find you could not answer, then the solutions will be published when the deadline for submissions is passed. So either way you will learn something.

Already have. I guess I will go through it again. I will share the code. I’ll see what happens I guess. Haven’t found any answers that have helped yet. And no docs that did either.

1 Like

Well nobody is actually meant to “give you the answers” so don’t expect to just trip over one and automatically pass.

I can confirm that I certainly have read the existing threads and there are indeed statements in there which basically tell you what to do anyway.

So if you are one of the people who replied with a “I’m having the same problem (sic)” then perhaps you should be following the same advice as was given to the person who raised “said problem”. Even if that person does not appear to be following the advice themselves.

Note that there’s extensive points on what to do if you did indeed change code ( or data ) somewhere else other than where you were instructed to.

I did not touch anything I was not supposed to. Neither do I want answers. I’ll just figure out somehow on my own. Thanks!

1 Like

Hi @interglobalmedia,

I would help you if I could, but unfortunately, I’m stuck in the same boat as you. I’ve posted examples and errors from the test tickets, etc…

Frankly, the tone here feels somewhat hostile. I’ve taken (and passed) quite a few courses here (including the older version of MongoDB for Node.js Developers, which has been replaced by this one), but have never encountered this tone here (@ Mongo U) before.

Don’t get discouraged. Not all of us here are experts. We are students. We ask questions. That’s what we’re supposed to do. :smiley:

2 Likes

Thanks Julliette! I’m not. I will eventually figure it out. Thanks for the vey encouraging and inspirational words!

1 Like

I was partly speaking to myself as well. :grinning:

I do that a lot too.

I passed all except the loginUser. Can’t figure out how to pass the parameter value.

Unlike addUser where the input that is sent to the function is an object with keys and values that can be used exactly as is (using the spread operator is handy for this one!), the sessions collection expects something different. It wants a document inserted like

  {  user_id: "some_email", jwt: "somelongjwt" }

Remember that upsert is your friend, and that you can pass an object like { jwt } and it will end up being {jwt: "somelongjwt"} when assigned.