Skip to content

phil2211/MDBMasterclassTutorialApp

Repository files navigation

Welcome to the MongoDB Atlas Demo App

This is a MongoDB Atlas App Services demo which shows how to implement several concepts of the Atlas App Services in combination with the powerful lucene based Atlas Search feature.

Some impressions of what you get

Pagination

Pagination

Cross Field Multi Match

Cross Field Multi Match

Fuzzy Search

Fuzzy Search

Live Update

Live Update

You can also find a quick overview by watching my presentation at MongoDB .local in Frankfurt. Click here for the video on YouTube

There is (still in german) a YouTube tutorial available which shows step by step how to build and use this app. You can find them here. English speaking audience: Please use subtitle to follow the tutorial. English version is in production ;-)

MongoDB Realm was renamed in summer 2022 to Atlas App Services

The following steps and features are available:

  1. Create testdata
  2. Merge data from two collections into one
  3. Scheduled Triggers and Functions (calculate age from birthday)
  4. Database Triggers and Functions (calculate total balance when account balance changes)
  5. First steps in Atlas App Services
  6. Imlementation of AG-Grid
  7. GraphQL
  8. Pagination
  9. Rowcount
  10. Introduction to Atlas Search
  11. Live updates using Server Sent Events SSE
  12. Advanced Search
  13. Fast Count and Facets

How to have fun :-)

Everything works on an Atlas Free Tier. No Credit Card needed, free forever

  1. Clone this repo and go to the directory
git clone https://github.com/phil2211/MDBMasterclassTutorialApp.git && \
cd MDBMasterclassTutorialApp
  1. You need the following prerequisits met to follow along

I use Homebrew to do this on MacOS. If you don't have Homebrew, please follow the very simple instructions on the Hombrew website to install it. The command below will install all necessary tools at once. If you are using Windows or Linux, see the links above for installation instructions for each component.

brew tap mongodb/brew && \
brew install mongodb-atlas-cli mongodb-database-tools node npm
  1. (optional) Generate the autocompletion script for your shell. Learn more following this link. Here the example for MacOS
atlas completion zsh > $(brew --prefix)/share/zsh/site-functions/_atlas
  1. Install mgenerate and the App Services CLI
npm install -g mgeneratejs atlas-app-services-cli
  • Restart your shell to use it

You can now follow the next steps manually or you just can execute the install.sh script to setup everything automatically


  1. Login to your Atlas account and choose your default project
atlas auth login -P MDBMasterclass
  1. Create a new project and a free cluster named MyCustomers
atlas projects create MDBMasterclass -P MDBMasterclass && \
atlas config set -P MDBMasterclass project_id `atlas -P MDBMasterclass project ls | grep MDBMasterclass | awk '{ print $1 }'` && \
atlas quickstart --skipMongosh --skipSampleData --provider AWS --region EU_CENTRAL_1 --tier M0 --username admin --password Passw0rd --accessListIp "0.0.0.0/0" --clusterName MyCustomers -P MDBMasterclass --force 
  1. Wait until the new created cluster is ready. Check for the state to become "IDLE"
atlas cluster get MyCustomers -P MDBMasterclass
  1. Load testdata to your cluster using the loadTestdata.sh script. Run the following command with your username password and the clusterId from your new created cluster
sh testData/loadTestdata.sh admin Passw0rd $(atlas cluster connectionstrings describe MyCustomers -P MDBMasterclass | grep "mongodb+srv" | awk -F. '{print $2}')
  1. Pre-calculate the age and totalBalance field by using the following MongoDB query in the mongoshell
mongosh $(atlas cluster connectionstrings describe MyCustomers -P MDBMasterclass | grep "mongodb+srv")/MyCustomers --apiVersion 1 --username admin --password Passw0rd --eval 'db.customerSingleView.updateMany(
    {},
    [{
      $set:
      {
        "totalBalance": {"$sum": "$accounts.balance"},
        "age": {
            "$subtract": [
                {"$subtract": [{"$year": "$$NOW"}, {"$year": "$birthdate"}]},
                {"$cond": [
                    {"$gt": [0, {"$subtract": [{"$dayOfYear": "$$NOW"},{"$dayOfYear": "$birthdate"}]}]},
                    1,
                    0
                ]}
            ]
        }
      }
    }]
  );'
  1. Create Atlas API keys for the appservices login
atlas project apiKeys create --desc appservices --role GROUP_OWNER -P MDBMasterclass > AtlasAPIKeys.txt
  1. Login your appservices using the new generated API-Key
appservices login --api-key $(cat AtlasAPIKeys.txt | grep "Public API Key" | awk '{ print $4 }') --private-api-key $(cat AtlasAPIKeys.txt | grep "Private API Key" | awk '{ print $4 }') -y --profile MDBMasterclass
  1. Import the backend code to Atlas using the appservices (Please select MDBMasterclass as target project when prompted)
appservices push --local "backend/MyCustomersGridApp" --include-package-json -y --profile MDBMasterclass && \
echo "REACT_APP_REALMAPP="$(appservices apps list --profile MDBMasterclass | grep mycustomersgridapp | awk '{print $1}') > frontend/.env.local
  1. Create an App user
appservices users create --type email --email test@example.com --password Passw0rd --profile MDBMasterclass -a $(appservices apps list --profile MDBMasterclass | grep mycustomersgridapp | awk '{print $1}')
  1. Create an Atlas Search index using the content of the following file
atlas clusters search indexes create -P MDBMasterclass -f "testData/AtlasSearchDefinitions/customEnhanced.json" --clusterName MyCustomers
  1. Install all dependencies for the frontend
cd frontend && \
npm install
  1. Start your frontend and login
npm start
  1. Wait for your browser to show the login page and log in using these credentials:
  • User: test@example.com
  • Password: Passw0rd

About

Every step from the video tutorial series

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published