SlideShare a Scribd company logo
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T
在 MongoDB Cloud上構建無服務器化應用
唐建法
大中國區首席架構師
MongoDB
• S e s s i o n I D
2
MongoDB at a glance
Revenue ($MM)
$114.8
$166.0
$267.0
FY17 FY18 FY19
• Headquartered in New York, NY
• 1,200+ global employees
• 13,400+ customers in over 100 countries
• 60MM+ total downloads of MongoDB
Community Server
• >120% net ARR expansion rate
over each of the last sixteen quarters
Note: Fiscal year ending January 31
Massive adoption of MongoDB
MongoDB vs. NoSQL skills on LinkedIn Activity index on Stack Overflow
-
20,000
40,000
60,000
80,000
100,000
120,000
2012 2013 2014 2015 2016
MongoDB Redis Cassandra Hbase Other
Other
HBase
Cassandra
Redis
More developers want to work with MongoDB this year than any other database
– Stack Overflow Developer Survey (2018)
Source: 451 Research Source: StackOverkill
Neo4j
HBase
Cassandra
Redis
Leading modern general purpose database
Creative
Cloud Fintech
Real-Time
Travel Search
Mobile Drug
Applications
Mobile
Banking
Multi-Screen
TV
Internet of
Things Platform
Predictive
Messaging
Background Checks
as a Service
Order
Capture
Cryptocurrency
Platform
Logistics
Modernization
E-Commerce
System
Entry Decision
System
Social Security
Benefits Program
Mobile App for
Patient Data
Product
Catalog
Single View
of Patient
Genetic
Analysis
Online
Lending
Swap Equities
Management
E-Commerce
Personalization
E-Commerce
Platform
Marketing
Cloud
Video
Streaming
Log Metadata
Store
Social Media
Management
Website
Platform
Product
Catalog
Identity Theft
Protection
Mass Spectrometer
Instrumentation
Subscriber
QoS
Shopping
Cart
Gaming Platform
Online Tax Returns Real-Time Analytics
social
MongoDB Atlas
Managed MongoDB in the Cloud
Customers have two choices: Self-managed or DBaaS
Cloud Migration
or Cloud First
Self-Managed
Aka “Lift and Shift”
Database as
a service
Slow and complicated
No elasticity
Highly manual
Reduces ROI and agility
Self-service
Fully elastic
Consumption based
Reduces TCO and accelerates
time to value
Fork in
the road
7
The TRAP of doing it yourself
Provision servers
Configure high availability
Configure security
Configure and test backup
Install and configure monitoring
Ongoing upgrades and maintenance
Application development
Performance optimization
Manual work is the hallmark of low-
performing IT organizations.
Deployments
64%
more manual work
Config. Mgmt.
65%
more manual work
Testing
40%
more manual work
2017 State of DevOps Report, Puppet
MongoDB Atlas — Global Cloud Database
Self-service & elastic
Deploy, modify, and upgrade on demand with
best-in-class operational automation
Automated database maintenance
Database and infrastructure resources as code
Scale up, out, or down in a few clicks or API calls
Global & cloud-agnostic
Available in 60+ regions across globe
Global clusters for read/write anywhere
deployments and multi-region fault tolerance
Easy migrations with a consistent experience
across cloud providers
Enterprise-grade security & SLAs
Network isolation, VPC peering, end-to-end
encryption, and role-based access controls
Encryption key management, LDAP integration,
granular database auditing
SOC 2 / Privacy Shield / HIPAA
Guaranteed reliability with SLAs
Comprehensive monitoring
Deep visibility into 100+ KPIs with proactive
alerting
Real-time performance tracking and
Performance Advisor
APIs to integrate with monitoring dashboards
Managed backup
Point-in-time data recovery
Queryable backup snapshots
Consistent snapshots of sharded deployments
Cloud data mobility
Stitch: Serverless platform services
Simple, serverless functions for backend logic,
service integrations, and APIs
Database access from your frontend secured by
straightforward, field-level access rules
Database and authentication triggers to react to
changes in real time
MongoDB as a service on AWS
MongoDB Atlas is currently available in 16 AWS regions.
• us-east-1 (N. Virginia)
• us-east-2 (Ohio)
• us-west-2 (Oregon)
• us-west-1 (N. California)
• ca-central-1 (Canada)
• sa-east-1 (São Paulo)
Americas
• ap-east-1 (Hong Kong)
• ap-southeast-1 (Singapore)
• ap-southeast-2 (Sydney)
• ap-northeast-1 (Tokyo)
• ap-northeast-2 (Seoul)
• ap-south-1 (Mumbai)
Asia
• eu-west-1 (Dublin)
• eu-west-2 (London)
• eu-west-3 (Paris)
• eu-north-1 (Stockholm)
• eu-central-1 (Frankfurt)
Europe
Highly available by default
• A minimum of three data nodes per replica set/shard are
automatically deployed across zones for high availability
• If your primary node does go down for any reason, the self
healing recovery process in MongoDB Atlas will typically occur
in under 2 seconds
Application
Driver
Primary
Secondary
Secondary
Replication
Cross-region replication
• Ensure uptime in the unlikely event of a multi-
zone or total region outage
• Get improved performance for local reads by
geographically distributing read-only replica set
members that do not participate in the failover
process
• Available for Atlas deployments running on
dedicated instances in AWS
Fine-grained monitoring and alerts
● Monitoring and alerts provide full metrics on the
state of your cluster’s database and server
usage
● Automatic notifications when your database
operations or server usage reach defined
thresholds that affect your cluster's performance
● Combining our automated alerting with the
flexible scale-up-and-out options in MongoDB
Atlas, we can keep your database-supported
applications always performing as well as they
should
Continuous backup
• MongoDB Atlas continuously backs up your data, ensuring
your backups are typically just a few seconds behind the
operational system
• Point-in-time backup of replica sets and consistent, cluster-
wide snapshots of sharded clusters. With MongoDB Atlas,
you can easily and safely restore to precisely the moment
you need
• Compression and block-level deduplication technology
keeps your backup processes as efficient as possible
• Backups are securely stored in North America, Ireland,
Germany, United Kingdom, or Australia*. For more location
flexibility of your backup data, you can utilize MongoDB’s
mongodump / mongorestore tools
*Additional regions for continuous backup coming soon
Global Clusters
Distribute your fully automated database across multiple
geographically distributed zones made up of one or
more cloud regions
● Read and write locally to provide single-digit
millisecond latency for your distributed applications
● Ensure that data from certain geographies lives in
predefined zones
● Easily deploy using prebuilt zone templates or
build your own zones by choosing cloud regions in
an easy-to-use, visual interface
Server-less with Atlas Stitch
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
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
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
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
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
在-MongoDB-Cloud-上構建無服務器化應用
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. Its 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
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!
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!
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.
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
We have connected to
the database and run
our first query! Check
the stitch console logs.
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.
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!
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.
The Server-less Architecture Accelerates Everything
Cloud Infrastructure
Services and APIs
Application Logic
MongoDB Atlas
Rapidly deploy, dynamically scale, and distribute
databases across regions and cloud providers
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 MongoDB Atlas + Stitch
Client Application or Service
Application Logic
DataData generated from your application is sent and retrieved
through the Stitch Client SDK
Thank you!
S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
唐建法
jianfa.tang@mongodb.com

More Related Content

在-MongoDB-Cloud-上構建無服務器化應用

  • 1. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T 在 MongoDB Cloud上構建無服務器化應用 唐建法 大中國區首席架構師 MongoDB • S e s s i o n I D
  • 2. 2 MongoDB at a glance Revenue ($MM) $114.8 $166.0 $267.0 FY17 FY18 FY19 • Headquartered in New York, NY • 1,200+ global employees • 13,400+ customers in over 100 countries • 60MM+ total downloads of MongoDB Community Server • >120% net ARR expansion rate over each of the last sixteen quarters Note: Fiscal year ending January 31
  • 3. Massive adoption of MongoDB MongoDB vs. NoSQL skills on LinkedIn Activity index on Stack Overflow - 20,000 40,000 60,000 80,000 100,000 120,000 2012 2013 2014 2015 2016 MongoDB Redis Cassandra Hbase Other Other HBase Cassandra Redis More developers want to work with MongoDB this year than any other database – Stack Overflow Developer Survey (2018) Source: 451 Research Source: StackOverkill Neo4j HBase Cassandra Redis
  • 4. Leading modern general purpose database Creative Cloud Fintech Real-Time Travel Search Mobile Drug Applications Mobile Banking Multi-Screen TV Internet of Things Platform Predictive Messaging Background Checks as a Service Order Capture Cryptocurrency Platform Logistics Modernization E-Commerce System Entry Decision System Social Security Benefits Program Mobile App for Patient Data Product Catalog Single View of Patient Genetic Analysis Online Lending Swap Equities Management E-Commerce Personalization E-Commerce Platform Marketing Cloud Video Streaming Log Metadata Store Social Media Management Website Platform Product Catalog Identity Theft Protection Mass Spectrometer Instrumentation Subscriber QoS Shopping Cart Gaming Platform Online Tax Returns Real-Time Analytics social
  • 6. Customers have two choices: Self-managed or DBaaS Cloud Migration or Cloud First Self-Managed Aka “Lift and Shift” Database as a service Slow and complicated No elasticity Highly manual Reduces ROI and agility Self-service Fully elastic Consumption based Reduces TCO and accelerates time to value Fork in the road
  • 7. 7 The TRAP of doing it yourself Provision servers Configure high availability Configure security Configure and test backup Install and configure monitoring Ongoing upgrades and maintenance Application development Performance optimization Manual work is the hallmark of low- performing IT organizations. Deployments 64% more manual work Config. Mgmt. 65% more manual work Testing 40% more manual work 2017 State of DevOps Report, Puppet
  • 8. MongoDB Atlas — Global Cloud Database Self-service & elastic Deploy, modify, and upgrade on demand with best-in-class operational automation Automated database maintenance Database and infrastructure resources as code Scale up, out, or down in a few clicks or API calls Global & cloud-agnostic Available in 60+ regions across globe Global clusters for read/write anywhere deployments and multi-region fault tolerance Easy migrations with a consistent experience across cloud providers Enterprise-grade security & SLAs Network isolation, VPC peering, end-to-end encryption, and role-based access controls Encryption key management, LDAP integration, granular database auditing SOC 2 / Privacy Shield / HIPAA Guaranteed reliability with SLAs Comprehensive monitoring Deep visibility into 100+ KPIs with proactive alerting Real-time performance tracking and Performance Advisor APIs to integrate with monitoring dashboards Managed backup Point-in-time data recovery Queryable backup snapshots Consistent snapshots of sharded deployments Cloud data mobility Stitch: Serverless platform services Simple, serverless functions for backend logic, service integrations, and APIs Database access from your frontend secured by straightforward, field-level access rules Database and authentication triggers to react to changes in real time
  • 9. MongoDB as a service on AWS MongoDB Atlas is currently available in 16 AWS regions. • us-east-1 (N. Virginia) • us-east-2 (Ohio) • us-west-2 (Oregon) • us-west-1 (N. California) • ca-central-1 (Canada) • sa-east-1 (São Paulo) Americas • ap-east-1 (Hong Kong) • ap-southeast-1 (Singapore) • ap-southeast-2 (Sydney) • ap-northeast-1 (Tokyo) • ap-northeast-2 (Seoul) • ap-south-1 (Mumbai) Asia • eu-west-1 (Dublin) • eu-west-2 (London) • eu-west-3 (Paris) • eu-north-1 (Stockholm) • eu-central-1 (Frankfurt) Europe
  • 10. Highly available by default • A minimum of three data nodes per replica set/shard are automatically deployed across zones for high availability • If your primary node does go down for any reason, the self healing recovery process in MongoDB Atlas will typically occur in under 2 seconds Application Driver Primary Secondary Secondary Replication
  • 11. Cross-region replication • Ensure uptime in the unlikely event of a multi- zone or total region outage • Get improved performance for local reads by geographically distributing read-only replica set members that do not participate in the failover process • Available for Atlas deployments running on dedicated instances in AWS
  • 12. Fine-grained monitoring and alerts ● Monitoring and alerts provide full metrics on the state of your cluster’s database and server usage ● Automatic notifications when your database operations or server usage reach defined thresholds that affect your cluster's performance ● Combining our automated alerting with the flexible scale-up-and-out options in MongoDB Atlas, we can keep your database-supported applications always performing as well as they should
  • 13. Continuous backup • MongoDB Atlas continuously backs up your data, ensuring your backups are typically just a few seconds behind the operational system • Point-in-time backup of replica sets and consistent, cluster- wide snapshots of sharded clusters. With MongoDB Atlas, you can easily and safely restore to precisely the moment you need • Compression and block-level deduplication technology keeps your backup processes as efficient as possible • Backups are securely stored in North America, Ireland, Germany, United Kingdom, or Australia*. For more location flexibility of your backup data, you can utilize MongoDB’s mongodump / mongorestore tools *Additional regions for continuous backup coming soon
  • 14. Global Clusters Distribute your fully automated database across multiple geographically distributed zones made up of one or more cloud regions ● Read and write locally to provide single-digit millisecond latency for your distributed applications ● Ensure that data from certain geographies lives in predefined zones ● Easily deploy using prebuilt zone templates or build your own zones by choosing cloud regions in an easy-to-use, visual interface
  • 16. 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
  • 17. 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
  • 18. 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
  • 19. 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
  • 20. 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
  • 22. 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. Its 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
  • 23. 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!
  • 24. 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!
  • 25. 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.
  • 26. 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 We have connected to the database and run our first query! Check the stitch console logs. 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.
  • 27. 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!
  • 28. 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.
  • 29. The Server-less Architecture Accelerates Everything Cloud Infrastructure Services and APIs Application Logic MongoDB Atlas Rapidly deploy, dynamically scale, and distribute databases across regions and cloud providers 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 MongoDB Atlas + Stitch Client Application or Service Application Logic DataData generated from your application is sent and retrieved through the Stitch Client SDK
  • 30. Thank you! S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. 唐建法 jianfa.tang@mongodb.com