Join Ben Perlmutter, senior solutions architect, to learn about the modernization of application development using a modern database with serverless compute. Learn how to quickly build a blog website backed by MongoDB while utilizing a serverless backend-as-a-service. We then add features and functionality with lightning speed, showing you a toolset that is designed to increase your productivity as a developer and enable you to focus on building product-differentiating code.
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Santa Clara AWS Summit.pdf
1. Expedite the Development Lifecycle with MongoDB & Serverless
Ben Perlmutter, Senior Solutions Architect
@ben_perlmutter
2. Agenda
MongoDB Atlas + Stitch
MongoDB as a Service
Backend as a Service
Stitch Tutorial
Basic Blog Website
The Art of the Possible
Other Examples and Tutorials
3. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
Typical Technology Stack
4. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
Utilize Database-as-a-Service
DBaaS
5. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
Add Backend-as-a-Service
DBaaS
BaaS
6. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
DBaaS
BaaS
You should focus here
And Focus Your Energy Where You Can Make a Difference
7. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
And Focus Your Energy Where You Can Make a Difference
MongoDB
Atlas
MongoDB
Stitch
You should focus here
Fully managed
Elastic scale
Highly available
Secure
9. MongoDB Stitch
Stitch QueryAnywhere
Brings MongoDB's rich
query language safely to
the edge
iOS, Android, Web, IoT
Stitch Functions
Integrate microservices +
server-side logic + cloud
services
Build full apps, or Data as a
Service through custom APIs
Stitch Mobile Sync
Automatically synchronizes
data between documents
held locally in MongoDB
Mobile and your backend
database
(coming soon)
Streamlines app development with simple, secure access to data and services from the client with thousands of fewer
lines of code to write and no infrastructure to manage – getting your apps to market faster while reducing operational
costs.
Stitch Triggers
Real-time notifications let your
application functions react in
response to database
changes, as they happen
10. The Broader IODP Accelerates Everything
Cloud Infrastructure
Services and APIs
Application Logic
MongoDB Atlas
Rapidly deploy, dynamically scale, and distribute
databases across regions
MongoDB Stitch
Serverless platform that allows developers to focus
on innovation rather than plumbing, services
orchestration, and boilerplate code
2-5x increase in productivity by leveraging the Intelligent Operational Data Platform
Client Application or Service
Application Logic
DataData generated from your application is sent and retrieved
through the Stitch Client SDK
14. Basic Blog Tutorial
<html>
<head>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on
the front page of hacker news. (In a good way)
</div>
<hr>
<div id="comments"></div>
</body>
</html>
Nothing special with the first step. It’s basic HTML.
Save the file as BasicBlogDemo.html and double click the file. It
will open in your browser.
You can see the header, the content and the hard rule at the
bottom
15. Basic Blog Tutorial
<html>
<head>
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.0/stitch.js"></script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news. (In a good way)
</div>
<hr>
<div id="comments"></div>
</body>
</html>
OK, we just now included the Stitch client browser SDK!
16. Basic Blog Tutorial
<html>
<head>
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.0/stitch.js"></script>
<script>
// Initialize the App Client
const client = stitch.Stitch.initializeDefaultAppClient("<your-app-id>");
// Get a MongoDB Service Client
const mongodb = client.getServiceClient(stitch.RemoteMongoClient.factory,"mongodb-
atlas");
// Get a reference to the blog database
const db = mongodb.db("blog");
</script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news.
(In a good way)
</div>
<hr>
<div id="comments"></div>
</body>
</html>
Stitch client browser SDK
Stitch APP ID
Stitch Client
Connection
Stitch Database
We now have
everything we need to
connect to the Atlas
database instance for
our application!
17. Basic Blog Tutorial
<html>
<head>
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.0/stitch.js"></script>
<script>
// Initialize the App Client
const client = stitch.Stitch.initializeDefaultAppClient("<your-app-id>");
// Get a MongoDB Service Client
const mongodb = client.getServiceClient(stitch.RemoteMongoClient.factory,"mongodb-atlas");
// Get a reference to the blog database
const db = mongodb.db("blog");
function displayComments() {
db.collection('comments').find({}, {limit: 1000}).asArray()
.then(docs => {
const html = docs.map(c => "<div>" + c.comment +
"</div>").join("");
document.getElementById("comments").innerHTML = html;
});
}
</script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news. (In a good
way)
</div>
<hr>
<div id="comments"></div>
</body>
</html>
Our first real function!
Then we display them
in the comments div as
html for the user to
view.
We specify the
comments collection.
We find the
documents, and
specify a limit of 1,000.
We Loop through the
array of documents
and store them in a
variable called html.
18. Basic Blog Tutorial
<html>
<head>
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.0/stitch.js"></script>
<script>
// Initialize the App Client
const client = stitch.Stitch.initializeDefaultAppClient("<your-app-id>");
// Get a MongoDB Service Client
const mongodb = client.getServiceClient(stitch.RemoteMongoClient.factory,"mongodb-atlas");
// Get a reference to the blog database
const db = mongodb.db("blog");
function displayComments() {
db.collection('comments').find({}, {limit: 1000}).asArray()
.then(docs => {
const html = docs.map(c => "<div>" + c.comment +
"</div>").join("");
document.getElementById("comments").innerHTML = html;
});
}
function displayCommentsOnLoad() {
client.auth
.loginWithCredential(new stitch.AnonymousCredential())
.then(displayComments)
.catch(console.error);
}
</script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news. (In a good
way)
</div>
<hr>
<div id="comments"></div>
</body onload="displayCommentsOnLoad()">
</html>
Our next function logs
us into our database.
It calls the display
comments function
after logging in.
The function to
connect to the
database is called in
the body onload...
Save the changes and
refresh the browser.
19. Basic Blog Tutorial
...
function addComment() {
const newComment = document.getElementById("new_comment");
console.log("add comment", client.auth.user.id)
db.collection("comments")
.insertOne({ owner_id : client.auth.user.id, comment: newComment.value })
.then(displayComments);
newComment.value = "";
}
function displayComments() {
db.collection('comments').find({}, {limit: 1000}).asArray()
.then(docs => {
const html = docs.map(c => "<div>" + c.comment +
"</div>").join("");
document.getElementById("comments").innerHTML = html;
});
}
...
</script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news. (In a good
way)
</div>
<hr>
Add comment:
<input id="new_comment"><BR>
<input type="submit" onClick="addComment()">
<hr
<div id="comments"></div>
</body onload="displayCommentsOnLoad()">
</html>
Now we insert a
comment into our Atlas
database through the
stitch API, and then
retrieve it for display.
The value we insert is
obtained from an input
field added here.
The add comment
function is called from
the submit button.
Our first Stitch app is
complete!
20. Basic Blog Tutorial
Play with it, add more comments.
Add new fields, see what happens.
You are well on your way to being
able to start writing a new
application.
You now have a basic
understanding and are ready for
more.