Evolving Your Data Access
with MongoDB Stitch
Wan BachtiarMongoDB {Sr. Technical Services Engineer,
Community }
@wanscale
@sindbach
Agenda
• MongoDB Stitch Overview
• Stitch Services:
• QueryAnywhere
• Stitch Functions
• Stitch Triggers
• Stitch Mobile Sync
Applications Are Evolving
Clients
Application
Server
Database
Rendering
Data
App Server
DatabaseIoT DevicesPhone
Browser
State
Logic
CRUDEmail
Queues Access Control
Payments
State
Sign
On
Service
Coordination
Image
s
Applications Are Evolving
Application Evolution
Application are living in more locations:
• More apps have back-ends deployed to a public
cloud*
• More apps are now developed for multiple
platforms*
More is expected of developers:
• More developers identified as full-stack*
More time spent on maintenance
Deploy and scale application seamlessly
Write standard code
Build simple and secure integrations
* https://insights.stackoverflow.com/survey
MongoDB Stitch
Rendering
Data
DatabaseIoT DevicesPhone
Browser
CRUD
Email
Queues
Access Control
Payments
State
Sign On
Service
Coordination
Images
Logic
State
Building Applications with Stitch
Traditional Applications….
• Contain many, separate layers
• Each layer is separate code, infrastructure
• Connecting/Maintaining layers is lots of work
Users
External
Services
Presentation
UI Components
UI Process
Components
Data Sources Services
Service
Interface
Business
Data
Application
Facade
Component
s
Workflo
w
Entities
Access
Component
s
Helper/
Utilities
Service
Agents
Security
Operational
Managemen
t
Building Applications with Stitch
Traditional Applications….
• Contain many, separate layers
• Each layer is separate code, infrastructure
• Connecting/Maintaining layers is lots of work
Building applications with Stitch....
• No infrastructure to scale/patch/manage
• Simplified service integrations
• Easy to configure security
• Hosted, serverless business logic
Users
External
Services
Data Sources Services
Stitch is comprised of four
services
QueryAnywhere
Brings MongoDB's rich
query language to your
application
Build full apps for iOS,
Android, Web, and IoT
Functions
Integrate server-side logic +
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)
Stitch QueryAnywhere
QueryAnywhere
Brings MongoDB's rich
query language to your
application
Build full apps for iOS,
Android, Web, and IoT
Functions
Integrate server-side logic +
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)
Stitch QueryAnywhere
• Write generic queries from applications
• Respond with precise information based on the request
SDKs:
• JavaScript (ES6), Android (Java), and iOS (Swift) SDKs
• Integrated authentication, access to database, and access to services
Stitch Rules:
• Fine-grained access rules relating to all aspects of Stitch
• Access to context from users, request, external services, functions, etc.
MongoDB Query Language + Native DriversIntegrated Rules
Functions3rd Party Services
Native SDKs (JavaScript, Android, iOS)
Rest API
How applications interact with Stitch
Request
User
Login
JWT
Filters
Roles
Rules
Stitch
Request
ResultsUser-specific
Results
Requests in Stitch
Example: Employee Directory
{
”userid":”101",
"name": "Bernice Herrera",
"employeeId": 53164957,
"zip": 2082,
"position": ”IT Manager",
"manager": "Ralph McBride",
"hiringDate": ISODate("2017-05-02"),
"employeeSource": "website ads",
"salary": 205000,
"gender": "female",
"dob": ISODate("1972-10-02"),
"citizenship": "Australia",
"email": ”bernice.herrera@example.com",
"empStatus": "active"
}
Sensitive
Information
Example: Employee Directory
You
Others
Sensitive
Information
Sensitive
Information
Filters in Stitch
User
db.collection.find()
(plus user info)
db.collection.find({“empStatus”: ”active"})
[{
userid: ”101"
name: …,
salary: …,
empStatus:”active”
},{
userid: ”404”
name: …,
salary: …,
empStatus: “terminated”,
}]
Results
{
"name": ”ActiveOnly",
"apply_when": {"%%true" : true},
"query": {”empStatus":"active"}
}
Filters contain an apply_when and a
Query which is appended to a request
[{
userid: ”101"
name: …,
salary: …,
empStatus:”active”
}]
Roles: Employee Directory
OwnData
Everyone
Sensitive
Information
Sensitive
Information
[{
userid: ”202"
name: …
salary: …
empStatus:”active”
},{
userid: ”101"
name: …
salary: …
empStatus: “active”}]
Roles are defined by Match statements,
evaluated per document, and assign a set of
Rules per document
User
{name: ”OwnData",
apply_when: {”userid":”%%user.id”},
fields: {…}
}
Roles : OwnData
[{
userid: ”202"
name: …
salary: …
empStatus:”active”
},{
userid: ”101"
name: …
salary: …
empStatus: “active”}]
userid: "%%user.id”userid: ”101”
db.collection.find()
(plus user info)
User
Each Role has a set of matching Rules that
define read and write access at the field-level
[{
userid: ”202"
name: …
salary: …
empStatus:”active”
},{
userid: ”101"
name: …
salary: …
empStatus: “active”}]
[{
userid: ”202"
name: …
salary: …
empStatus:”active”
},{
name: …
salary: …}]
Rules : OwnData
"fields": {
“name” :{ “read”: true},
”salary":{"read": true}
},
"additional_fields": {
"read": false,
"write": false
}
Roles are defined by Match statements,
evaluated per document, and assign a set of
Rules per document
User
Roles : Everyone
{name: ”Everyone",
apply_when: {”%%true":true},
fields: {…}
}
[{
userid: ”202"
name: …
salary: …
empStatus:”active”
},{
name: …
salary: …}]
[{
userid: ”202"
name: …
salary: …
empStatus:”active”
},{
name: …
salary: …}]
User
Each Role has a set of matching Rules that
define read and write access at the field-level
[{
userid: ”202"
name: …
salary: …
empStatus:”active”
},{
name: …
salary: …}]
[{
name: …
},{
name:…
salary: …
}]
Rules : Everyone
"fields": {
“name” :{ “read”: true},
},
"additional_fields": {
"read": false,
"write": false
}
Roles: Employee Directory
OwnData
Everyone
{
userid: “202”
name: …
salary: …
empStatus: ”active”
}
{
userid: “101”
name: …
salary: …
empStatus: ”active”
}
{
name: …
salary: …
}
{
name: …
}
{
"filters": [{
"name": ”ActiveOnly",
"apply_when": {"%%true" : true},
"query": {”empStatus":”active"}
}, … ],
"roles": [{
name: ”OwnData"
apply_when: {“userid”:”%%user.id”}
"fields": {
”name": {"read": true},
“salary”: {“read”: true}}
},
"additional fields": {
"read": false,
"write": false
}}, … ],
"schema": {…}
}
Filters
Roles
Rules
Schema
Stitch Rules
schema: {
bsonType: "object",
required: ["userid", ”email", ”salary"],
properties: {
userid: {
bsonType: ”string",
description: "The ID of the Stitch user"
},
email: {
bsonType: "string",
description: "must be a string and is required"
},
salary: {
bsonType: ”integer",
description: ”must be an integer and is required"
}
}
JSON Schema
schema: {
bsonType: "object",
required: ["userid", ”email", ”salary"],
properties: {
userid: {
bsonType: ”string",
description: "The ID of the Stitch user"
},
email: {
bsonType: "string",
validate: {"%%true": {
"%function": {
"name": "isValid",
"arguments": ["%%user", "%%this"]}
}},
description: "must be a string and is required"
},
salary: {
bsonType: ”integer",
description: ”must be an integer and is required"
}
[...]
Schema Validation
Simple Rules User-Interface
• Visual Rules
• Simple Read/Write rules
• Ideal for getting started
Stitch Rules
Exposing Data via API
const stitchClient = stitch.initializeDefaultAppClient(‘dotlocal');
// Connect to a MongoDB Atlas database
const coll = stitchClient
.getServiceClient(RemoteMongoClient.factory, 'mongodb-atlas')
.db(‘hr')
.collection(‘employee');
// 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 JSON Web Token)
// 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(…)
Stitch Services
const twilio = stitchClient.getServiceClient(
TwilioServiceClient.factory, "myTwilioService");
// Twilio: send text messages
twilio.sendMessage(toPhone, fromPhone, 'A message from Stitch!')
.then(() => console.log('success!’));
// SES: send email messages
sesService.send(fromEmail, toEmail, message)
.then(() => … );
// S3: put data in AWS S3
s3Service.put(bucket, key, acl, contentType)
.then(() => … );
Stitch Functions
QueryAnywhere
Brings MongoDB's rich
query language to your
application
Build full apps for iOS,
Android, Web, and IoT
Functions
Integrate server-side logic +
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)
• Scalable, hosted JavaScript (ES6)
Functions
• Integrated with application context :
User, Request, Services, Values, etc.
Stitch Functions
Stitch Functions
addtoCart calcStats sendText
Application
(Stitch SDK)
MongoDB
// Send a text message to all Database Administrators
client.executeFunction(‘sendText’,
‘Database Administrator’,
‘Cluster is OK’);
Stitch Functions
Stitch Functions
//Function sendText
exports = function(position, message) {
let mongodb = context.services.get("mongodb-atlas");
let twilio = context.services.get("twilio");
let emp = mongodb.db(”hr").collection(”employee").find({”position": position});
let statuses = [];
return Promise.all(emp).then(doc => {
for (let i in emp) {
statuses.push(twilio.send(context.values.get("twilioPhone")), doc[i].Phone, message);
}
return Promise.all(statuses);
});
}
Stitch Triggers
QueryAnywhere
Brings MongoDB's rich
query language to your
application
Build full apps for iOS,
Android, Web, and IoT
Functions
Integrate server-side logic +
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)
Stitch Triggers
• Register a Trigger
• Stitch creates, maintains Change Stream
• Monitors for changes
• Runs Functions on matching changes
Stitch Triggers
Benefits:
• React to database events in real-time
• Respond with hosted JavaScript functions
• Separate resources from database
• Access to broad application context
• Fully managed environment
Stitch Functions
MongoDB
addtoCart calcStats
… sendMail
employe
e
Stitch Mobile Sync
QueryAnywhere
Brings MongoDB's rich
query language to your
application
Build full apps for iOS,
Android, Web, and IoT
Functions
Integrate server-side logic +
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)
Stitch Mobile Sync (Beta)
A mobile-optimised version of the MongoDB
database that runs locally on the device,
enabling offline access to data.
Stitch SDKs that manage the lower-level
database operations and provide methods to
interact with MongoDB Mobile and the Stitch
backend
MongoDB Mobile
Stitch Mobile Sync
MongoDB employe
e
MongoDB Mobile
Application
Stitch SDK
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 real-time
• Simple conflict resolution
• Fully-managed solution
Simple & Cheap Consumption Pricing
• Streamlined with Atlas
Compute
Free Tier: 1,000,000 functions or 100,000GB-s /month
Additional Usage:
• $0.000025 per GB-s for Compute
• Runtime - Length of request in milliseconds
• Memory - Max memory used in MB
Data Transfer
Free Tier: 25 GB /month
Additional Usage:
• $.5/GB Data Downloaded
• Transfer to Atlas is free
Pricing
• Check out another talk on Stitch –
• Get started with Stitch – stitch.mongodb.com
• Check out SDKs and examples
• docs.mongodb.com/stitch
• github.com/mongodb/stitch-examples
• Check out other talks on Stitch :
• MongoDB Mobile: Bringing the Power of MongoDB to Your Device - 1:10pm
• MongoDB Stitch Tutorial (Workshop) – 4:45pm
• Ask questions and/or let MongoDB know what you are building
Next Steps
Thank You!
Appendix
Develop with Stitch – Stitch CLI
• 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
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
| ...
Develop with Stitch – Console
• Stitch Console
• Run functions in the Stitch UI
• Spoof specific users to test permissions
Develop with Stitch – Logs
Stitch Logs
• Information on all requests run
• Get info on: results. runtime,
errors, billing, etc.
• Easy to sort/filter/download

MongoDB.local Sydney: Evolving your Data Access with MongoDB Stitch

  • 1.
    Evolving Your DataAccess with MongoDB Stitch
  • 2.
    Wan BachtiarMongoDB {Sr.Technical Services Engineer, Community } @wanscale @sindbach
  • 3.
    Agenda • MongoDB StitchOverview • Stitch Services: • QueryAnywhere • Stitch Functions • Stitch Triggers • Stitch Mobile Sync
  • 4.
  • 5.
    Rendering Data App Server DatabaseIoT DevicesPhone Browser State Logic CRUDEmail QueuesAccess Control Payments State Sign On Service Coordination Image s Applications Are Evolving
  • 6.
    Application Evolution Application areliving in more locations: • More apps have back-ends deployed to a public cloud* • More apps are now developed for multiple platforms* More is expected of developers: • More developers identified as full-stack* More time spent on maintenance Deploy and scale application seamlessly Write standard code Build simple and secure integrations * https://insights.stackoverflow.com/survey
  • 7.
    MongoDB Stitch Rendering Data DatabaseIoT DevicesPhone Browser CRUD Email Queues AccessControl Payments State Sign On Service Coordination Images Logic State
  • 8.
    Building Applications withStitch Traditional Applications…. • Contain many, separate layers • Each layer is separate code, infrastructure • Connecting/Maintaining layers is lots of work Users External Services Presentation UI Components UI Process Components Data Sources Services Service Interface Business Data Application Facade Component s Workflo w Entities Access Component s Helper/ Utilities Service Agents Security Operational Managemen t
  • 9.
    Building Applications withStitch Traditional Applications…. • Contain many, separate layers • Each layer is separate code, infrastructure • Connecting/Maintaining layers is lots of work Building applications with Stitch.... • No infrastructure to scale/patch/manage • Simplified service integrations • Easy to configure security • Hosted, serverless business logic Users External Services Data Sources Services
  • 10.
    Stitch is comprisedof four services QueryAnywhere Brings MongoDB's rich query language to your application Build full apps for iOS, Android, Web, and IoT Functions Integrate server-side logic + 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)
  • 11.
    Stitch QueryAnywhere QueryAnywhere Brings MongoDB'srich query language to your application Build full apps for iOS, Android, Web, and IoT Functions Integrate server-side logic + 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)
  • 12.
    Stitch QueryAnywhere • Writegeneric queries from applications • Respond with precise information based on the request SDKs: • JavaScript (ES6), Android (Java), and iOS (Swift) SDKs • Integrated authentication, access to database, and access to services Stitch Rules: • Fine-grained access rules relating to all aspects of Stitch • Access to context from users, request, external services, functions, etc.
  • 13.
    MongoDB Query Language+ Native DriversIntegrated Rules Functions3rd Party Services Native SDKs (JavaScript, Android, iOS) Rest API How applications interact with Stitch
  • 14.
  • 15.
    Example: Employee Directory { ”userid":”101", "name":"Bernice Herrera", "employeeId": 53164957, "zip": 2082, "position": ”IT Manager", "manager": "Ralph McBride", "hiringDate": ISODate("2017-05-02"), "employeeSource": "website ads", "salary": 205000, "gender": "female", "dob": ISODate("1972-10-02"), "citizenship": "Australia", "email": ”bernice.herrera@example.com", "empStatus": "active" } Sensitive Information
  • 16.
  • 17.
    Filters in Stitch User db.collection.find() (plususer info) db.collection.find({“empStatus”: ”active"}) [{ userid: ”101" name: …, salary: …, empStatus:”active” },{ userid: ”404” name: …, salary: …, empStatus: “terminated”, }] Results { "name": ”ActiveOnly", "apply_when": {"%%true" : true}, "query": {”empStatus":"active"} } Filters contain an apply_when and a Query which is appended to a request [{ userid: ”101" name: …, salary: …, empStatus:”active” }]
  • 18.
  • 19.
    [{ userid: ”202" name: … salary:… empStatus:”active” },{ userid: ”101" name: … salary: … empStatus: “active”}] Roles are defined by Match statements, evaluated per document, and assign a set of Rules per document User {name: ”OwnData", apply_when: {”userid":”%%user.id”}, fields: {…} } Roles : OwnData [{ userid: ”202" name: … salary: … empStatus:”active” },{ userid: ”101" name: … salary: … empStatus: “active”}] userid: "%%user.id”userid: ”101” db.collection.find() (plus user info)
  • 20.
    User Each Role hasa set of matching Rules that define read and write access at the field-level [{ userid: ”202" name: … salary: … empStatus:”active” },{ userid: ”101" name: … salary: … empStatus: “active”}] [{ userid: ”202" name: … salary: … empStatus:”active” },{ name: … salary: …}] Rules : OwnData "fields": { “name” :{ “read”: true}, ”salary":{"read": true} }, "additional_fields": { "read": false, "write": false }
  • 21.
    Roles are definedby Match statements, evaluated per document, and assign a set of Rules per document User Roles : Everyone {name: ”Everyone", apply_when: {”%%true":true}, fields: {…} } [{ userid: ”202" name: … salary: … empStatus:”active” },{ name: … salary: …}] [{ userid: ”202" name: … salary: … empStatus:”active” },{ name: … salary: …}]
  • 22.
    User Each Role hasa set of matching Rules that define read and write access at the field-level [{ userid: ”202" name: … salary: … empStatus:”active” },{ name: … salary: …}] [{ name: … },{ name:… salary: … }] Rules : Everyone "fields": { “name” :{ “read”: true}, }, "additional_fields": { "read": false, "write": false }
  • 23.
    Roles: Employee Directory OwnData Everyone { userid:“202” name: … salary: … empStatus: ”active” } { userid: “101” name: … salary: … empStatus: ”active” } { name: … salary: … } { name: … }
  • 24.
    { "filters": [{ "name": ”ActiveOnly", "apply_when":{"%%true" : true}, "query": {”empStatus":”active"} }, … ], "roles": [{ name: ”OwnData" apply_when: {“userid”:”%%user.id”} "fields": { ”name": {"read": true}, “salary”: {“read”: true}} }, "additional fields": { "read": false, "write": false }}, … ], "schema": {…} } Filters Roles Rules Schema Stitch Rules
  • 25.
    schema: { bsonType: "object", required:["userid", ”email", ”salary"], properties: { userid: { bsonType: ”string", description: "The ID of the Stitch user" }, email: { bsonType: "string", description: "must be a string and is required" }, salary: { bsonType: ”integer", description: ”must be an integer and is required" } } JSON Schema
  • 26.
    schema: { bsonType: "object", required:["userid", ”email", ”salary"], properties: { userid: { bsonType: ”string", description: "The ID of the Stitch user" }, email: { bsonType: "string", validate: {"%%true": { "%function": { "name": "isValid", "arguments": ["%%user", "%%this"]} }}, description: "must be a string and is required" }, salary: { bsonType: ”integer", description: ”must be an integer and is required" } [...] Schema Validation
  • 27.
    Simple Rules User-Interface •Visual Rules • Simple Read/Write rules • Ideal for getting started Stitch Rules
  • 28.
  • 29.
    const stitchClient =stitch.initializeDefaultAppClient(‘dotlocal'); // Connect to a MongoDB Atlas database const coll = stitchClient .getServiceClient(RemoteMongoClient.factory, 'mongodb-atlas') .db(‘hr') .collection(‘employee');
  • 30.
    // Authenticate, thenadd 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 JSON Web Token)
  • 31.
    // Authenticate, thenquery 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(…)
  • 32.
  • 33.
    const twilio =stitchClient.getServiceClient( TwilioServiceClient.factory, "myTwilioService"); // Twilio: send text messages twilio.sendMessage(toPhone, fromPhone, 'A message from Stitch!') .then(() => console.log('success!’)); // SES: send email messages sesService.send(fromEmail, toEmail, message) .then(() => … ); // S3: put data in AWS S3 s3Service.put(bucket, key, acl, contentType) .then(() => … );
  • 34.
    Stitch Functions QueryAnywhere Brings MongoDB'srich query language to your application Build full apps for iOS, Android, Web, and IoT Functions Integrate server-side logic + 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)
  • 35.
    • Scalable, hostedJavaScript (ES6) Functions • Integrated with application context : User, Request, Services, Values, etc. Stitch Functions Stitch Functions addtoCart calcStats sendText Application (Stitch SDK) MongoDB
  • 36.
    // Send atext message to all Database Administrators client.executeFunction(‘sendText’, ‘Database Administrator’, ‘Cluster is OK’); Stitch Functions
  • 37.
  • 38.
    //Function sendText exports =function(position, message) { let mongodb = context.services.get("mongodb-atlas"); let twilio = context.services.get("twilio"); let emp = mongodb.db(”hr").collection(”employee").find({”position": position}); let statuses = []; return Promise.all(emp).then(doc => { for (let i in emp) { statuses.push(twilio.send(context.values.get("twilioPhone")), doc[i].Phone, message); } return Promise.all(statuses); }); }
  • 39.
    Stitch Triggers QueryAnywhere Brings MongoDB'srich query language to your application Build full apps for iOS, Android, Web, and IoT Functions Integrate server-side logic + 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)
  • 40.
    Stitch Triggers • Registera Trigger • Stitch creates, maintains Change Stream • Monitors for changes • Runs Functions on matching changes
  • 41.
    Stitch Triggers Benefits: • Reactto database events in real-time • Respond with hosted JavaScript functions • Separate resources from database • Access to broad application context • Fully managed environment Stitch Functions MongoDB addtoCart calcStats … sendMail employe e
  • 42.
    Stitch Mobile Sync QueryAnywhere BringsMongoDB's rich query language to your application Build full apps for iOS, Android, Web, and IoT Functions Integrate server-side logic + 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)
  • 43.
    Stitch Mobile Sync(Beta) A mobile-optimised version of the MongoDB database that runs locally on the device, enabling offline access to data. Stitch SDKs that manage the lower-level database operations and provide methods to interact with MongoDB Mobile and the Stitch backend MongoDB Mobile Stitch Mobile Sync MongoDB employe e MongoDB Mobile Application Stitch SDK
  • 44.
    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 real-time • Simple conflict resolution • Fully-managed solution
  • 45.
    Simple & CheapConsumption Pricing • Streamlined with Atlas Compute Free Tier: 1,000,000 functions or 100,000GB-s /month Additional Usage: • $0.000025 per GB-s for Compute • Runtime - Length of request in milliseconds • Memory - Max memory used in MB Data Transfer Free Tier: 25 GB /month Additional Usage: • $.5/GB Data Downloaded • Transfer to Atlas is free Pricing
  • 46.
    • Check outanother talk on Stitch – • Get started with Stitch – stitch.mongodb.com • Check out SDKs and examples • docs.mongodb.com/stitch • github.com/mongodb/stitch-examples • Check out other talks on Stitch : • MongoDB Mobile: Bringing the Power of MongoDB to Your Device - 1:10pm • MongoDB Stitch Tutorial (Workshop) – 4:45pm • Ask questions and/or let MongoDB know what you are building Next Steps
  • 47.
  • 48.
  • 49.
    Develop with Stitch– Stitch CLI • 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 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 | ...
  • 50.
    Develop with Stitch– Console • Stitch Console • Run functions in the Stitch UI • Spoof specific users to test permissions
  • 51.
    Develop with Stitch– Logs Stitch Logs • Information on all requests run • Get info on: results. runtime, errors, billing, etc. • Easy to sort/filter/download

Editor's Notes

  • #2 Today we’ll be talking about how to evolve your data access with MongoDB Stitch
  • #3 A MongoDB Community TSE based in Sydney. We interact with the broader MongoDB community globally, provide technical answers in StackExchange sites and Google Group forums, with the goal to help the community in adopting MongoDB.
  • #5 Applications is always changing. We used to have thick client architectures, which evolved in into thin client architectures, as shown here , this is kind of state of an application look like - On one end you had the database storing all your data, on the other side you had your client, phone, browser or IOT device. There wasn’t much rendering on that side. Now what’s happened in the recent years in the application back-end, is we’ve gone from a database and a big application server with state, logic and all the different functionalities to - A state where we have more and more being pushed to the database and client, the browser side/phone side now keep state, logic and more processing, the database is keeping states as well. Those things now have been offloaded off the application server little bit now - There’s also lots of services, whether it’s image processing, email, sign-on, payments, and these have been offloaded into either microservice or third-party services such as SES for sending email, Twillio for sending txt messages, Google/Facebook, Stripe, etc Slowly and slowly instead of having a big monolithic application server, things move into different layers, and application server only focuses on 3 things : * CRUD: read write to the database * Access Control : as requests coming in make sure the right data is exposed * Service Coordination: integration between services, and everything flow seamlessly
  • #6 Applications is always changing. We used to have thick client architectures, which evolved in into thin client architectures, as shown here , this is kind of state of an application look like - On one end you had the database storing all your data, on the other side you had your client, phone, browser or IOT device. There wasn’t much rendering on that side. Now what’s happened in the recent years in the application back-end, is we’ve gone from a database and a big application server with state, logic and all the different functionalities to - A state where we have more and more being pushed to the database and client, the browser side/phone side now keep state, logic and more processing, the database is keeping states as well. Those things now have been offloaded off the application server little bit now - There’s also lots of services, whether it’s image processing, email, sign-on, payments, and these have been offloaded into either microservice or third-party services such as SES for sending email, Twillio for sending txt messages, Google/Facebook, Stripe, etc Slowly and slowly instead of having a big monolithic application server, things move into different layers, and application server only focuses on 3 things : * CRUD: read write to the database * Access Control : as requests coming in make sure the right data is exposed * Service Coordination: integration between services, and everything flow seamlessly
  • #7 The application evolution is responding to environment Application are living in more locations: Most applications are being developed for multiple platforms, smart phones, smart watches More is expected of developers than ever: Full-stack development becoming the standard Too much of their time is spent on boring, boilerplate code: More and more hours are spent developing/maintaining existing vs. on new projects** This includes frontend, backend, services, and database More is being expected of Applications than ever: More web/mobile apps have their backend deployed to a public cloud platform* Higher demands for data distribution and seamless integration with cloud services Simplify things to focus on your business logic
  • #8 This is really the goal of building MongoDB Stitch : Thinking about where the state of application architecture is going, Being the platform or connecting tissue between the three. By providing simple tools and layers to build resilient application.
  • #10 Clarify external services / services
  • #11 Stitch gives you the ability via SDKs, services and rules to issue commands to your database from just about everywhere. Whether services, incoming requests, applications or REST API, and combined with Stitch rules to serve just the right amount of information back. This really serve to augment QueryAnywhere, to write server side logic in a hosted JavaScript functions with standard ES6. You can call it from service actions, REST API requests or SDKs. Also have access to contexts and everything still respects Rules that you defined. Triggers help you to responds immediately to changes happening in the database. Build on top of ChangeStream, monitor changes and execute functions based on those changes Working with MongoDB Mobile on your device, let you sync seamlessly between your device and your back-end The goal of these four is to provide a seamless workflow for users.
  • #13 Two concepts to help you : First is SDKs , to help you form and send requests to Stitch. To make sure those requests are executed correctly with the correct permission is with Stitch Rules. Fine-grained… Rules in Stitch not only have access to the data, but also the context. So you can make these rules decision based on the user who’s making the requests, where it’s coming from, and you can make calls to external services or functions, to make decision whether certain access is permitted or not.
  • #14 We tend to break the Stitch down to few layers to understand how requests flow in Stitch. On the top layers, we have SDKs. These SDKs are built on-top of a REST API that gives you access to the database, external services, and functions. But they all are protected by a layer of rules Something to point out, when you’re building with Stitch, it can live along side of your existing applications that reads existing database in Atlas.
  • #15 This is why Stitch takes the Place of the application server Atlas provides: Simple Scaling/ Management at the Database level Ability to access from multiple Stitch Applications Additional validation logic with JSON Schema Stitch provides: Layer of server-side logic Ability to set strict API access rules Declarative Database Access rules supporting integration with external systems Stitch SDKs provide: Simple access to MongoDB and Services within Stitch Familiar Syntax Integrated authentication JSON WEB TOKEN (JWT) mentioned Explain Filters/ Roles/Rules
  • #16 Let’s use an example to explore Stitch Rules further
  • #17 A user should be able to see their own sensitive information, but should not be able to see colleagues sensitive information
  • #18 You can define filters on incoming queries that Stitch evaluates and applies before its initial query to your MongoDB cluster. Adding a filter to a collection can improve query performance by reducing the number of documents for which Stitch needs to evaluate a role. You can also use a filter to redact specific fields from queried documents.
  • #19 A user should be able to see their own sensitive information, but should not be able to see colleagues sensitive information
  • #20 Userid make distinct
  • #21 Make notice of the other role (all access)
  • #22 Userid make distinct
  • #23 Make notice of the other role (all access)
  • #24 A user should be able to see their own sensitive information, but should not be able to see colleagues sensitive information
  • #25 Putting it all together …
  • #26 Apply a schema to your database. Introduced in MongoDB v3.6. Stitch adopts the same type schema, what it lets you do is when users are pushing data changes to your database, then JSON schema make sure that those data is valid. All of those writes conform to the right type or schema.
  • #27 Stitch differs in one aspect then MongoDB JSON schema, which is validate. Validate lets you run a function, to see whether the data is valid. Is the data in the right length, values, and run function. If returns True then it’s valid, else it’s invalid.
  • #30 Getting start with an app like I just showed is easy, we’re going to skip ahead of installing the js sdk, and you just start by creating a new Stitch client instance and pointing it to the Atlas instance that you linked to Stitch After that you can point it to any database and collection within your instance Now, to make a request, you just need to authenticate the client From there you can use simple and familiar syntax to access your data. You can pretty much complete whatever CRUD options you like within the code The same way that you define and work with MongoDB can also be extended to other patner services. It’s quite simple to link a service to Stitch in the UI, and then reference it and kick-off actions in your application code. Consistent with mongodb drivers api
  • #34 See with Stitch, all you need to do is provide the identifying information for your service, such as a key. Stitch stores and encrypts these keys so there is no need to have a separate management service for your application. Once the link is made you can reference these services and use pre-built actions to reference them from your code. For instance you can: Create a slack service and post a message to slack Create a twilio service and send a text message with twilio Or even do something more complex, like creating an S3 service and using it to upload data to S3 You can even use our HTTP service to integrate your own favorite service or API Now, the great thing is that these actions don’t live in isolation, they can interact with each other to produce complex interactions, and this is where pipelines come in.
  • #36 Getting start with an app like I just showed is easy, we’re going to skip ahead of installing the js sdk, and you just start by creating a new Stitch client instance and pointing it to the Atlas instance that you linked to Stitch After that you can point it to any database and collection within your instance From there you can use simple and familiar syntax to access your data. You can pretty much complete whatever CRUD options you like within the code The same way that you define and work with MongoDB can also be extended to other partner services. It’s quite simple to link a service to Stitch in the UI, and then reference it and kick-off actions in your application code.
  • #37 Getting start with an app like I just showed is easy, we’re going to skip ahead of installing the js sdk, and you just start by creating a new Stitch client instance and pointing it to the Atlas instance that you linked to Stitch After that you can point it to any database and collection within your instance From there you can use simple and familiar syntax to access your data. You can pretty much complete whatever CRUD options you like within the code The same way that you define and work with MongoDB can also be extended to other partner services. It’s quite simple to link a service to Stitch in the UI, and then reference it and kick-off actions in your application code.
  • #39 Getting start with an app like I just showed is easy, we’re going to skip ahead of installing the js sdk, and you just start by creating a new Stitch client instance and pointing it to the Atlas instance that you linked to Stitch After that you can point it to any database and collection within your instance From there you can use simple and familiar syntax to access your data. You can pretty much complete whatever CRUD options you like within the code The same way that you define and work with MongoDB can also be extended to other partner services. It’s quite simple to link a service to Stitch in the UI, and then reference it and kick-off actions in your application code.
  • #44 As an app developer, you are typically faced with constructing separate logic for storing data both in the cloud and on the device. Just as MongoDB Stitch simplifies much of the backend logic for you, it also provides a unified SDK for storing data in both Atlas and on the device, using MongoDB Mobile. With MongoDB Mobile, you use a single query language for local and remote data access
  • #45 As an app developer, you are typically faced with constructing separate logic for storing data both in the cloud and on the device. Just as MongoDB Stitch simplifies much of the backend logic for you, it also provides a unified SDK for storing data in both Atlas and on the device, using MongoDB Mobile. With MongoDB Mobile, you use a single query language for local and remote data access MongoDB Mobile ?