Feel free to re-use the cluster you created for the previous week’s challenges if you have one. Otherwise, you can build a new free tier instance.
1. Launch a free MongoDB Atlas M0 instance.
2. If you already have a cluster with the sample data loaded, drop all the sample databases. This is necessary as we’re going to simulate sales data by loading the
3. Create a Stitch application with a global deployment region.
4. Review the sample_supplies document model, as the fields in this document structure, will be used to create a
5. Let’s now create a stitch trigger called
countSales. Set the configuration for the trigger as follows.
a. The database name needs to be
sample_supplies. Remember, this is one of the sample databases we loaded from step 2.
b. The collection name needs to be sales, this collection will be created when we load the sample data.
c. We will only look for Insert (or create) operations.
d. Be sure to set the match expression of the trigger to meet the requirements we described above.
e. Create a function called
sales_counter. This function should return a count of the number of documents that match our criteria.
6. Now edit functions settings:
a. The function should be private.
b. The function should run as system, this will allow us to access the database without the need to create rules.
7. Let's edit the function code using the web-based editor:
a. The function should increment a field called total in the
sales_output collection each time an event is triggered which meets our requirements.
8. Now let's load the sample data to generate events which will be captured by our trigger.
9. Once everything has run, submit your trigger code, match expression, and results by clicking the green 'submit' button below.
You have until Monday, May 20th, at 5:00pm (Eastern Daylight Time) to submit your answers.