- ❓ What do we do in the
Server
andUserController
constructors to set up our connection to the development database? - ❓ How do we retrieve a user by ID in the
UserController.getUser(String)
method? - ❓ How do we retrieve all the users with a given age
in
UserController.getUsers(Map...)
? What's the role offilterDoc
in that method? - ❓ What are these
Document
objects that we use in theUserController
? Why and how are we using them? - ❓ What does
UserControllerSpec.clearAndPopulateDb
do? - ❓ What's being tested in
UserControllerSpec.getUsersWhoAre37()
? How is that being tested? - ❓ Follow the process for adding a new user. What role do
UserController
andUserRequestHandler
play in the process?
-
The server gets the MongoDB named dev, then it passes that to the UserController, which looks for a collection in the database called users.
-
The getUser() method takes an id as a string for its argument and then it searches a database for an id that matches the id it was given. If there is a match, it returns the information of that user, else returns null because the id wasn't found.
-
The getusers method gets a map of parameters, and an if statement checks if age is a parameter, then it adds the age to the filterDoc, then Mongo uses the filterDoc to search for matches, and then it updates the collection with the matching users.
-
The document objects tell Mongo which keys to look for, and then finds the users with matching values for those keys. We need the keys because it reduces the likelihood of finding duplicated values inside of each user.
-
It gets the MongoDb, then it clears it and populates it with new data that you give it for testing. This lets you have a small database for testing, and you always know whats in the database.
-
It gets all the users that are age 37, then tests that only 2 were found, and that those two have the right names.
-
The userRequestHandler gets the information from the webpage and converts that information into integers and strings, then passes that information to the userController method addNewUser. The userController uses that information to create a document, and then sends that document to the database.