Adding the new collections

Open your MongoDB shell and execute the following:

  use OrderBase;
  db.createCollection('User');
  db.createCollection('Role');
  db.createCollection('AccessToken');

This will create the necessary collections that we need to store users and their roles and tokens. The new documents will have the following structure:

User:
{
    firstName,
    lastName,
    email,
    roleID,
    password
}

For now, we will not add any users or tokens (this comes later when we extend the API), but we will add the roles that we are going to use. To keep it simple, we will just have two of them:

  • Producer: This is the user who sells goods in the shop and who can add additional products to it.
  • Customer: This is the user who buys things from the shop and who can create orders and retrieve information about products as well as orders that were created by the current user.

It is understood that default ObjectID generated by MongoDB will be included in the preceding code. For the access token entity, we simply use ObjectID as the hash of the token, since this value is guaranteed to be unique with respect to the database that we are working with.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.199.184