{"id":685,"date":"2017-11-14T12:25:17","date_gmt":"2017-11-14T20:25:17","guid":{"rendered":"https:\/\/www.kenwalger.com\/blog\/?p=685"},"modified":"2018-01-11T06:32:57","modified_gmt":"2018-01-11T14:32:57","slug":"mongodb-stitch-tutorial","status":"publish","type":"post","link":"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-stitch-tutorial\/","title":{"rendered":"MongoDB Stitch Tutorial"},"content":{"rendered":"<p>I have talked about <a href=\"https:\/\/www.mongodb.com\">MongoDB<\/a>&#8216;s Backend as a Service (BaaS) Stitch <a href=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodbs-baas-offering-stitch\/\">previously<\/a>. In this post, let&#8217;s take a look at a basic Stitch application and how easy it is to get started. For this particular tutorial, we&#8217;ll be looking at basic Stitch functionality. However, I&#8217;ll point out some options along the way for extending the application.<\/p>\n<h3>The Stitch Application Overview<\/h3>\n<p>For this tutorial, let&#8217;s imagine an application that <a href=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/flask-blood-glucose-tracker\/\">tracks blood glucose<\/a> for <a href=\"https:\/\/www.amazon.com\/gp\/product\/0470178116\/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0470178116&amp;linkCode=as2&amp;tag=kenwalgersite-20&amp;linkId=6d2f297c507bd99bca135dd52fc33e60\" target=\"_blank\" rel=\"noopener\">diabetic patients<\/a><img loading=\"lazy\" decoding=\"async\" style=\"border: none !important; margin: 0px !important;\" src=\"\/\/ir-na.amazon-adsystem.com\/e\/ir?t=kenwalgersite-20&amp;l=am2&amp;o=1&amp;a=0470178116\" alt=\"\" width=\"1\" height=\"1\" border=\"0\" \/>. A blood sugar monitor, like the <a href=\"https:\/\/www.amazon.com\/gp\/product\/B06WWBFRVL\/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B06WWBFRVL&amp;linkCode=as2&amp;tag=kenwalgersite-20&amp;linkId=1a3970fd7847b18e062083d1f5c6f0e2\" target=\"_blank\" rel=\"noopener\">One Drop Chrome<\/a><img loading=\"lazy\" decoding=\"async\" style=\"border: none !important; margin: 0px !important;\" src=\"\/\/ir-na.amazon-adsystem.com\/e\/ir?t=kenwalgersite-20&amp;l=am2&amp;o=1&amp;a=B06WWBFRVL\" alt=\"\" width=\"1\" height=\"1\" border=\"0\" \/>,\u00a0would send results to our application. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Endocrinology\">Medical practitioners<\/a> could see the results and leave comments on the reading. While beyond the scope of this tutorial, Stitch can integrate with a service such as <a href=\"https:\/\/www.twilio.com\">Twilio<\/a> to send the comments via SMS message to the patient for diabetic management suggestions. From a development perspective, this can be integrated with MongoDB 3.6 <a href=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/change-streams-coming-soon-mongodb-3-6\/\">Change Streams<\/a> as well.<\/p>\n<p>A sample application page is available to view <a href=\"https:\/\/kenwalger.com\/stitch\/glucose.html\">here<\/a> with working comments attached to a <a href=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-atlas\/\">MongoDB Atlas<\/a> cluster and using Stitch. Let&#8217;s see how it was generated.<\/p>\n<h3>Cloud Services<\/h3>\n<p>Stitch runs on top of Atlas so we&#8217;ll need to set those services up.<\/p>\n<h6>Atlas<\/h6>\n<p>First off we&#8217;ll need to <a href=\"https:\/\/cloud.mongodb.com\/user?nds=true#\/login?nds=true\">log into<\/a> MongoDB Atlas\u00a0or create an account. Then we&#8217;ll need to set up an Atlas Cluster. There is an option for an M0 level which is free and doesn&#8217;t require a credit card to get started. This is a great feature to be able to try out this incredible service.<\/p>\n<p>Stitch is currently only located in the AWS US East 1 region so it is best to set your cluster up in that region for optimal performance. Once the cluster is configured, deployed, and initialized we&#8217;ll move onto setting up Stitch.<\/p>\n<h6>Stitch<\/h6>\n<p>To get started setting up a Stitch application, in the MongoDB Atlas console, select the\u00a0<em>Stitch App<\/em> option.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"689\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-stitch-tutorial\/attachment\/stitch_app_selection\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_selection.png?fit=303%2C508&amp;ssl=1\" data-orig-size=\"303,508\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"stitch_app_selection\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_selection.png?fit=303%2C508&amp;ssl=1\" class=\"aligncenter size-medium wp-image-689\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_selection.png?resize=179%2C300&#038;ssl=1\" alt=\"Stitch Application Selection\" width=\"179\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_selection.png?resize=179%2C300&amp;ssl=1 179w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_selection.png?w=303&amp;ssl=1 303w\" sizes=\"auto, (max-width: 179px) 85vw, 179px\" \/><\/p>\n<p>Then the\u00a0<em>Create New Application<\/em> button in the upper right. Give the application a name, I&#8217;m calling this application\u00a0<strong>glucose<\/strong>, and select the MongoDB Atlas Cluster you want to connect to.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"694\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-stitch-tutorial\/attachment\/new_stitch_application-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/new_stitch_application-1.png?fit=849%2C843&amp;ssl=1\" data-orig-size=\"849,843\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"new_stitch_application\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/new_stitch_application-1.png?fit=840%2C834&amp;ssl=1\" class=\"aligncenter size-medium wp-image-694\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/new_stitch_application-1.png?resize=300%2C298&#038;ssl=1\" alt=\"New Stitch App\" width=\"300\" height=\"298\" srcset=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/new_stitch_application-1.png?resize=300%2C298&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/new_stitch_application-1.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/new_stitch_application-1.png?resize=768%2C763&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/new_stitch_application-1.png?w=849&amp;ssl=1 849w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>It will take a minute to spin up the new application. Once it is up and running, we&#8217;ll want to set authentication to\u00a0<em>Anonymous Authentication<\/em>.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"693\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-stitch-tutorial\/attachment\/anon_auth\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/anon_auth.png?fit=1221%2C272&amp;ssl=1\" data-orig-size=\"1221,272\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"anon_auth\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/anon_auth.png?fit=840%2C187&amp;ssl=1\" class=\"aligncenter size-medium wp-image-693\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/anon_auth.png?resize=300%2C67&#038;ssl=1\" alt=\"Anonymous Authentication\" width=\"300\" height=\"67\" srcset=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/anon_auth.png?resize=300%2C67&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/anon_auth.png?resize=768%2C171&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/anon_auth.png?resize=1024%2C228&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/anon_auth.png?resize=1200%2C267&amp;ssl=1 1200w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/anon_auth.png?w=1221&amp;ssl=1 1221w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>There are a few pieces of information we&#8217;ll need from this screen for our application. For this tutorial, we&#8217;ll be using the\u00a0information from\u00a0<em>JS(Browser)<\/em> but it is great to see support for Node.js, iOS, and Android configurations as well.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"691\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-stitch-tutorial\/attachment\/stitch_client_settings\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_client_settings.png?fit=1500%2C1050&amp;ssl=1\" data-orig-size=\"1500,1050\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"stitch_client_settings\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_client_settings.png?fit=840%2C588&amp;ssl=1\" class=\"aligncenter size-medium wp-image-691\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_client_settings.png?resize=300%2C210&#038;ssl=1\" alt=\"Stitch client setting strings\" width=\"300\" height=\"210\" srcset=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_client_settings.png?resize=300%2C210&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_client_settings.png?resize=768%2C538&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_client_settings.png?resize=1024%2C717&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_client_settings.png?resize=1200%2C840&amp;ssl=1 1200w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_client_settings.png?w=1500&amp;ssl=1 1500w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>We&#8217;ll want to grab the <code>&lt;script&gt;<\/code> information from the\u00a0<em>Importing on a Webpage<\/em> bit and add that to our HTML that we&#8217;ll generate. We&#8217;ll also need the App Id listed later on as well. But first, let&#8217;s setup our database and collection. We&#8217;ll want to click\u00a0<em>mongodb-atlas<\/em> from the left navigation panel and then the\u00a0<em>Rules<\/em> tab.<\/p>\n<h6>Connect the Database<\/h6>\n<p>Click\u00a0<em>NEW<\/em> to add a new MongoDB <a href=\"https:\/\/docs.mongodb.com\/master\/core\/databases-and-collections\/\">collection<\/a>. For the database, I&#8217;ve called mine <strong>glucose<\/strong> and I called the collection\u00a0<strong>results<\/strong>. Now we&#8217;ll need to configure some permissions to allow, for the purposes of this tutorial, anyone to read the comments. Obviously, with sensitive and private medical data we would want to set the permissions to be more strict.<\/p>\n<p>Under the\u00a0<em>Rules<\/em>\u00a0tab, click on the collection you just created and proceed to the\u00a0<em>Filters<\/em> tab.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"697\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-stitch-tutorial\/attachment\/stitch_app_filters\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_filters.png?fit=1045%2C491&amp;ssl=1\" data-orig-size=\"1045,491\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"stitch_app_filters\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_filters.png?fit=840%2C395&amp;ssl=1\" class=\"aligncenter size-medium wp-image-697\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_filters.png?resize=300%2C141&#038;ssl=1\" alt=\"\" width=\"300\" height=\"141\" srcset=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_filters.png?resize=300%2C141&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_filters.png?resize=768%2C361&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_filters.png?resize=1024%2C481&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_filters.png?w=1045&amp;ssl=1 1045w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>Delete this existing filter and click\u00a0<em>SAVE<\/em>. Now head on over to the\u00a0<em>Field Rules<\/em> tab. In the\u00a0<em>Permissions for top-level document<\/em> section, we&#8217;ll want to change the\u00a0<em>Read<\/em> rule to <code>{}<\/code> and click\u00a0<em>SAVE<\/em>.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"696\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-stitch-tutorial\/attachment\/stitch_app_field_rules\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_field_rules.png?fit=1052%2C1042&amp;ssl=1\" data-orig-size=\"1052,1042\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"stitch_app_field_rules\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_field_rules.png?fit=840%2C832&amp;ssl=1\" class=\"aligncenter size-medium wp-image-696\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_field_rules.png?resize=300%2C297&#038;ssl=1\" alt=\"\" width=\"300\" height=\"297\" srcset=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_field_rules.png?resize=300%2C297&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_field_rules.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_field_rules.png?resize=768%2C761&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_field_rules.png?resize=1024%2C1014&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/11\/stitch_app_field_rules.png?w=1052&amp;ssl=1 1052w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>With these settings, we are allowing anyone to read any records in <code>glucose.results<\/code>, but only the owners can edit or delete their own comments. Stitch has integration with services such as Facebook and Google via OAuth. Further, custom <a href=\"https:\/\/docs.mongodb.com\/stitch\/authentication\/\">authentication <\/a>is possible with JSON Web Tokens.<\/p>\n<h3>Stitch the Application to the HTML<\/h3>\n<p>Now that we&#8217;ve set up our Stitch application on the backend, we need to integrate it into our HTML page. For this tutorial, we&#8217;re generating a static page with fake data. However, in a real application, we would use some dynamic content. At any rate, let&#8217;s see how we can proceed.<\/p>\n<h6>HTML<\/h6>\n<p>We&#8217;ll generate a basic HTML page with our <code>&lt;script&gt;<\/code> information in the <code>&lt;head&gt;<\/code> section. And we&#8217;ll include a form at the end to be able to get input from our medical professionals.<\/p>\n<pre>&lt;!doctype html&gt;\n&lt;html lang=\"en\"&gt;\n    &lt;head&gt;\n        &lt;meta charset=\"utf-8\"&gt;\n        &lt;meta http-equiv=\"x-ua-compatible\" content=\"ie-edge\"&gt;\n        &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n        &lt;title&gt;Blood Glucose&lt;\/title&gt;\n        &lt;script src=\"https:\/\/s3.amazonaws.com\/stitch-sdks\/js\/library\/stable\/stitch.min.js\"&gt;&lt;\/script&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;h2&gt;Sample Blood Glucose Report&lt;\/h2&gt;\n        &lt;div&gt;\n            &lt;p&gt;Patient Id: 12345&lt;\/p&gt;\n            &lt;p&gt;Date: 5 November 2017&lt;\/p&gt;\n            &lt;p&gt;Time: 07:23am&lt;\/p&gt;\n            &lt;p&gt;Reading was taken: Before Breakfast&lt;\/p&gt;\n            &lt;p&gt;Result: 110&lt;\/p&gt;\n            &lt;hr&gt;\n            &lt;div id=\"comments\"&gt;\n            &lt;\/div&gt;\n            &lt;hr&gt;\n            &lt;form&gt;\n                &lt;label for=\"new_comment\"&gt;Add Comments:&lt;\/label&gt;\n                &lt;input id=\"new_comment\"&gt;\n                &lt;input class=\"button\" type=\"submit\"&gt;\n            &lt;\/form&gt;\n        &lt;\/div&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>Let&#8217;s also think about what we&#8217;re trying to do with our JavaScript and add in the appropriate hooks in our HTML before we tackle our JavaScript.<\/p>\n<p>Since we want our comments to load when the page does, let&#8217;s add an <code>onload<\/code> to the <code>&lt;body&gt;<\/code> tag:<\/p>\n<pre>&lt;body onload=\"displayCommentsOnLoad()\"&gt;<\/pre>\n<p>We&#8217;ll also need to add an on click listener to our form:<\/p>\n<pre>&lt;input class=\"button\" type=\"submit\" onClick=\"addComment()\"&gt;<\/pre>\n<p>Nice. It seems like, then, that we have three JavaScript functions to write to get our functionality implemented. The two mentioned and a third <code>displayComments<\/code>\u00a0seems like it will be necessary. Let&#8217;s tackle those functions next in <code>glucose.js<\/code>.<\/p>\n<h6>JavaScript<\/h6>\n<p><code>glucose.js<\/code><\/p>\n<pre>const client = new stitch.StitchClient('glucose-XXXXX');\nconst db = client.service('mongodb', 'mongodb-atlas').db('glucose');\n\nfunction displayCommentsOnLoad() {\n    client.login().then(displayComments();\n}\n\nfunction displayComments() {\n    db.collection('results').find({}).then(docs =&gt; {\n        const html = docs.map(c =&gt; \"&lt;div&gt;\" + c.comment + \"&lt;\/div&gt;\").join(\"\");\n        document.getElementByID(\"comments\").innerHTML = html;\n    });\n}\n\nfunction addComment() {\n    const foo = document.getElementById(\"new_comment\");\n    db.collection(\"results\").insert({owner_id : client.authedId(), comment : foo.value}).then(displayComments);\n    foo.value = \"\";\n}<\/pre>\n<p>You&#8217;ll want to alter the <code>glucose-XXXXX<\/code> to utilize the App Id for your own application and if you are using a different database and\/or collection names, make those changes as well.<\/p>\n<p>We&#8217;ll also need to add the script to our HTML in the <code>&lt;head&gt;<\/code> section:<\/p>\n<pre>&lt;script src=\"glucose.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>I have the completed <a href=\"https:\/\/github.com\/kenwalger\/intro_to_stitch\">project code<\/a>, with some minimal <a href=\"https:\/\/foundation.zurb.com\/\">Foundation<\/a> styling available on GitHub as well.<\/p>\n<h3>Wrap Up<\/h3>\n<p>And that&#8217;s it! Neat. We now have a basic web page that will accept comments from a user (medical professional) and, through the power of Stitch, save the comments in <span style=\"background-color: rgba(246, 213, 217, 0.804);\">a\u00a0<\/span>MongoDB Atlas hosted database. Stitch has provided the backend power and we just had to write some minimal <a href=\"https:\/\/www.javascript.com\/\">JavaScript<\/a> functions to handle the button click and document insert into our collection.<\/p>\n<hr \/>\n<p>Follow me on Twitter <a href=\"https:\/\/www.twitter.com\/kenwalger\">@kenwalger<\/a> to get the latest updates on my postings. Or better yet, sign up for the email list to get updates in your mailbox!<\/p>\n<p>There are a few MongoDB specific terms in this post. I created a <a href=\"https:\/\/www.echoskillstore.com\/MongoDB-Dictionary\/45103\">MongoDB Dictionary<\/a> skill for the <a href=\"https:\/\/www.amazon.com\/gp\/product\/B01DFKC2SO\/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B01DFKC2SO&amp;linkCode=as2&amp;tag=kenwalgersite-20&amp;linkId=f9e513223de2525a72b95cf9561db55b\" rel=\"noopener noreferrer\">Amazon Echo<\/a>\u00a0line of products. Check it out and you can say &#8220;Alexa, ask MongoDB for the definition of a\u00a0document?&#8221; and get a helpful response.<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F685&#038;t=MongoDB%20Stitch%20Tutorial&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F685&#038;p&#091;images&#093;&#091;0&#093;=https%3A%2F%2Fi0.wp.com%2Fwww.kenwalger.com%2Fblog%2Fwp-content%2Fuploads%2F2017%2F06%2Fmongodbstitch-e1498689024596.png%3Ffit%3D125%252C125%26ssl%3D1&#038;p&#091;title&#093;=MongoDB%20Stitch%20Tutorial\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/facebook.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F685&#038;text=Hey%20check%20this%20out\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/twitter.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-reddit nolightbox\" data-provider=\"reddit\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Reddit\" href=\"https:\/\/www.reddit.com\/submit?url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F685&#038;title=MongoDB%20Stitch%20Tutorial\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"reddit\" title=\"Share on Reddit\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/reddit.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F685&#038;title=MongoDB%20Stitch%20Tutorial\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/linkedin.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=MongoDB%20Stitch%20Tutorial&#038;body=Hey%20check%20this%20out:%20https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F685\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/mail.png?resize=48%2C48&#038;ssl=1\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>I have talked about MongoDB&#8216;s Backend as a Service (BaaS) Stitch previously. In this post, let&#8217;s take a look at a basic Stitch application and how easy it is to get started. For this particular tutorial, we&#8217;ll be looking at basic Stitch functionality. However, I&#8217;ll point out some options along the way for extending the &hellip; <a href=\"https:\/\/www.kenwalger.com\/blog\/nosql\/mongodb\/mongodb-stitch-tutorial\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;MongoDB Stitch Tutorial&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":417,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pmpro_default_level":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,4],"tags":[72],"yst_prominent_words":[1227,123,89,1114,1127,1128,117,1111,1120,1122,1129,87,1113,1116,1121,1126,805,1107,417,1109],"class_list":["post-685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-mongodb","tag-stitch","pmpro-has-access"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2017\/06\/mongodbstitch-e1498689024596.png?fit=125%2C125&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8lx70-b3","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/comments?post=685"}],"version-history":[{"count":6,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/685\/revisions"}],"predecessor-version":[{"id":771,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/685\/revisions\/771"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/media\/417"}],"wp:attachment":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/media?parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/categories?post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/tags?post=685"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}