4. Rendering
Data
App ServerDatabase IoT DevicesPhone
Browser
State
Logic
CRUD Email
QueuesAccess Control
Payments
State
Sign On
Service
Coordination
Image
Processi
ng
Applications are evolving
5. How is development evolving?
Applications are living in more locations:
• 48% of apps have back ends deployed to a public cloud
• 58% of apps are now developed for multiple platforms
More is expected of development:
• 64% of developers identified as full-stack (2017)
Too much time is spent on maintenance
• 41% of time spent maintaining
• 39% on new projects
Deploy and scale your application seamlessly
Write straightforward, standard code
Build simple, secure integrations
6. Presentation
UI Components
UI Process Components
Business
Business
Workflow
Business
Components
Business
Entities
Application Facade
Data
Data Access
Components
Data Helper
Utilities
Server
Agents
Data Sources Services
Users
External
Systems
Service
Interfac
e
CrossCutting
Security
OperationalManagement
Communication
Traditional Applications….
• Contain many, separate layers
• Each layer is separate code, infrastructure
• Connecting/Maintaining layers is lots of work
Building an Application with Stitch
Securit
y
&
Auth
Integratio
n
Business Logic
Data Access
Hosting
7. Traditional Applications….
• Contain many, separate layers
• Each layer is separate code, infrastructure
• Connecting/Maintaining layers is lots of work
Building an Application with Stitch
Building applications with Stitch....
• No infrastructure to scale/patch/manage
• Simplified service integrations
• Easy to configure security
• Hosted, serverless business logic
Presentation
UI Components
UI Process Components
Business
Business
Workflow
Business
Components
Business
Entities
Application Facade
Data
Data Access
Components
Data Helper
Utilities
Server
Agents
Data Sources Services
Users
External
Systems
8. Stitch is comprised of 4 services –
QueryAnywhere
Simple, streamlined syntax
for data access, robust
access rules, hosting
included
Build full apps for iOS,
Android, Web, and IoT
Functions
Integrate server-side logic +
microservices + cloud
services
Power apps with Server-side
logic, or enable Data as a
Service with custom APIs.
Triggers
Real-time notifications let your
application functions react in
response to database changes
App responds immediately to
change
Mobile Sync
Automatically synchronizes
data between documents
held locally in MongoDB
Mobile and your backend
database
(Beta)
9. MongoDB Query Language + Native DriversIntegrated Rules
Functions3rd Party Services
Native SDKs (JavaScript, Android, iOS)
Rest API
Stitch QueryAnywhere
11. Filters in Stitch
User
db.collection.find()
(plus user info)
db.collection.find({userid: "%%user.id"})db.collection.find({userid: "5b2..."})
[{
userid: "5b2..."
data: …
isSecret: false
},{
userid: "5b2..."
data: …
isSecret: true
}]
Results
{
"name": "userId",
"apply_when": {"%%true" : "%%true"},
"query": {"userid":"%%user.id"}
}
Filters contain an ApplyWhen and a
Query which is appended to a request
12. [{
userid: "5b2..."
data: …
isSecret: false
},{
userid: "5b2..."
data: …
isSecret: true
}]
Roles are defined by Match statements,
evaluated per document, and assign a set of
Rules per document
User
{name: "Not Secret Data",
apply_when: {"isSecret": false},
fields: {…}
}
[{
userid: "5b2..."
data: …
isSecret: false
}]
Roles in Stitch
13. User
Rules in Stitch
"fields": {
"data": {"read": true}
},
"additional_fields": {
"read": false,
"write": false
}
Each Role has a set of matching Rules that
define read and write access at the field-level
[{
userid: "5b2..."
data: …
isSecret: false
}]
[{
data: …
}]
16. schema: {
bsonType: "object",
required: ["userid", "data", "isSecret"],
properties: {
userid: {
bsonType: "objectid",
description: "The ID of the Stitch user"
},
data: {
bsonType: "string",
description: "must be a string and is not required"
},
isSecret: {
bsonType: "bool",
description: "True if the data is a secret"
}
additionalProperties: false
}
JSON Schema
17. schema: {
bsonType: "object",
required: ["userid", "data", "isSecret"],
properties: {
userid: {
bsonType: "objectid",
description: "The ID of the Stitch user"
},
data: {
bsonType: "string",
validate: {"%%true": {"%function": {
"name": "isValid",
"arguments": ["%%user", "%%this"]}}}
description: "must be a string and is not required"
},
isSecret: {
bsonType: "bool",
description: "True if the data is a secret"
}
[...]
Schema Validation
18. # M D B l o c a l
const stitchClient = stitch.initializeDefaultAppClient('myApp');
// Connect to a MongoDB Atlas database
const coll = stitchClient
.getServiceClient(RemoteMongoClient.factory, 'mongodb-atlas')
.db('Demo')
.collection('Users');
MongoDB Services Functions
Stitch Concepts
19. # M D B l o c a l
// Authenticate, then add and retrieve documents.
stitchClient.auth.loginWithCredential(
// You can use loginWithCredential() to access any auth provider
// Providers include:
// - Anonymous
// - Email/Password
// - Facebook
// - Google
// - API Keys
// - Custom (signed JWT)
MongoDB Services Functions
Stitch Concepts
20. # M D B l o c a l
// Authenticate, then query the database
stitchClient.auth.loginWithCredential(new AnonymousCredential())
.then(() =>
coll.find().asArray()
).then(users =>
...
);
// Or execute almost any CRUD/Aggregate command
coll.find({})
.aggregate([…])
.count(…)
.deleteMany(…) / .deleteOne(…)
.insertMany(…) / .insertOne(…)
.updateMany(…) / .updateOne(…)
MongoDB Services Functions
Stitch Concepts
21. # M D B l o c a l
const twilio = stitchClient.getServiceClient(
TwilioServiceClient.factory, "myTwilioService");
twilio.sendMessage(toPhone, fromPhone, 'A message from Stitch!')
.then(() => console.log('success!'));
sesService.send(fromEmail, toEmail, message)
.then(() => … );
s3Service.put(bucket, key, acl, contentType)
.then(() => … );
MongoDB Services Functions
Stitch Concepts
22. Stitch Functions
Stitch is a collection of servers that
process application requests
Requests:
• Single actions for Database or Services
• Or executing a Stitch Function
• Integrated with Stitch’s rules
Functions:
• Scalable, hosted JavaScript (ES6) Functions
• Integrated with application context
• User, Request, Services, Values, etc.
Stitch Functions
addtoCart calcStats
… sendMail
Application
(Stitch SDK)
MongoDB
23. # M D B l o c a l
client.callFunction('sendWeather', ‘Atlanta');
MongoDB Services Functions
Stitch Concepts
24. # M D B l o c a l
client.callFunction('sendWeather', ‘Atlanta');
MongoDB Services Functions
Stitch Concepts
exports = function(city) {
let mongodb = context.services.get("mongodb-atlas");
let UserColl = mongodb.db("StitchDemo").collection("Users");
let twilio = context.services.get("twilio");
let weather = context.services.get("weatherAPI");
let users = UserColl.find({"city": city});
let forecast = weather.get({context.values.get("weatherURL") + city});
let statuses = [];
return Promise.all(users, forecast).then(data => {
for(var i in data.users){
statuses.push(twilio.send(context.values.get("twilio")), data.users[i].Phone, data.forecast);
}
return Promise.all(statuses);
});
}
25. Stitch Triggers
Stitch Triggers
• Register a Trigger in your app
• Stitch creates, maintains Change Stream
• Monitors for changes
• Runs Functions on matching changes
Benefits of Stitch Triggers
• React to database events in real-time
• Respond with hosted JavaScript functions
• Separate resources from database
• Fully managed environment
• Access to broad application context
Stitch Functions
MongoDB
addtoCart calcStats
… sendMail
order
27. Stitch Mobile Sync (Beta)
Stitch Mobile Sync (Beta)
• Define a list of documents to Sync
• Define client-side change/conflict handling
• Use the Stitch SDK to seamless operate locally and
remotely – even when your application is offline
Benefits of Mobile Sync
• Simplify end-to-end application creation
• Enable applications to operate offline
• React to backend changes in realtime
• Simple conflict resolution
• Fully-managed, serverless solution
Stitch Mobile Sync
MongoDB order
MongoDB Mobile
Application
Stitch SDK
28. • Import/Export your application configuration
• Develop with Stitch locally
• Add to repositories for versioning and
collaboration
• Easily move code between environments
• Use structure from existing apps to create
something new
Develop with Stitch – Stitch CLI
yourStitchApp/
├── stitch.json
├── auth_providers/
│ └── <provider name>.json
├── functions/
│ └── <function name>/
│ ├── config.json
│ └── source.js
├── services/
│ └── <service name>/
│ ├── config.json
│ ├── incoming_webhooks/
│ │ ├── config.json
│ │ └── source.js
│ └── rules/
│ └── <rule name>.json
| ...
29. Develop with Stitch – Console and Logs
Stitch Console
• Run functions in the Stitch UI
• Spoof specific users to test
permissions
Stitch Logs
• Information on all requests run
• Get info on: results. runtime,
errors, billing, etc.
• Easy to sort/filter/download
30. Develop with Stitch – Console and Logs
Stitch Console
• Run functions in the Stitch UI
• Spoof specific users to test
permissions
Stitch Logs
• Information on all requests run
• Get info on: results. runtime,
errors, billing, etc.
• Easy to sort/filter/download
31. • Get started with Stitch – stitch.mongodb.com
• Check out SDKs and examples –
• Code at github.com/mongodb/stitch-examples
• Docs at docs.mongodb.com/stitch
• Build the Dashboard or IoT apps in our Tutorials section
What next?