MongoDB Stitch

Backend as a Service

Configure your application backend in the cloud.

Follow the tutorials

Full access to MongoDB, declarative read/write
controls, and integration with your choice of services

MongoDB Stitch lets developers focus on building applications rather than on managing data manipulation code, service integration, or backend infrastructure. Whether you’re just starting up and want a fully managed backend as a service, or you’re part of an enterprise and want to expose existing MongoDB data to new applications, Stitch lets you focus on building the app users want, not on writing boilerplate backend logic.

Stitch gives developers full access to MongoDB, the ability to declare fine-grained data access controls, and composability with other services. Initially Stitch is available for MongoDB Atlas.

All of MongoDB

Unlike other backend offerings, get the full power and scalability of MongoDB – whether using your existing database or starting from scratch. Retain direct access to the database.

Declarative data access controls

Control which fields a user can read or write to by defining simple JSON rules. Grant others access to approved aggregations while maintaining data privacy.

Service integrations

Built-in integrations make it simple for your app to use leading third party services and auth APIs without locking you into a single provider. Include internal microservices using Stitch's HTTP service.

Service pipelines

Easily orchestrate data across multiple services by configuring multi-stage pipelines; where each stage acts on the data before passing its results on to the next. Invoke pipelines through the Stitch API or WebHooks.

REST-like API

The easiest way to work with MongoDB and other backend services. Client SDKs for JavaScript, Android, and iOS enable cross-platform client support.

Existing application data

Safely expose selected fields from an existing database to a new application. New apps can add additional data to the same database.

Makes development easy

MongoDB Stitch lets you write rules and service integrations in a simple, declarative manner – making it easy to get started, extend, and maintain your application.

Choose your step

Here we show you how to point Stitch to a MongoDB collection. Then we show an anonymous login, document insert, and find operation.

// It’s simple to point Stitch to any MongoDB collection
const client = new stitch.StitchClient('myApp');
const db = client.service('mongodb', 'myMongoDB').db('production');

// Anonymously authenticate, then add and retrieve documents.
client.login()
  .then(function () {
    return db.collection('items')
      .insert({'owner_id': client.authedId(), 'number': 42})
  })
  .then(function () {
    return db.collection('items').find({})
  })
  .then(function (docs) {
    return docs.forEach(function (doc, index) {
      console.log('Document // ', index, ':', JSON.stringify(doc))
    })
  });
// Define access rules at the document or field level.
// Safe access by default.
// {
//   'owner_id': '%%user.id'
// }
 
// Create precise, powerful rules by augmenting them with
// built-in expansion functions like ‘%user’
// as well as the MongoDB Aggregation framework.
// {
//   '%or': [
//     { 'owner_id': '%%user.id'},
//     { '%%prev': { '%%exists': false } }
//   ]
// }
 
// Rules can govern MongoDB or determine whether a service
// or pipeline is accessible
// 3rd party services can be defined and accessed directly
// from the application code.
const slackService = client.service('slack', 'mySlackService');
 
// Services come with built-in actions that leverage
// their core features with little code. 
slackService.post('stitchChannel', 'user123', 'Hi Slack!')
  .then(function () {
    alert('posted to slack!')
  });

// These actions can also be executed as single stage pipelines
client.executePipeline([
  slackService.post('stitchChannel', 'user123', 'Hi Slack!')
]);
// executePipeline lets you execute a single database
// or service actions from your application.  
const mdb = client.service(‘mongodb’, ‘mdb1’);
const tw = client.service(‘twilio’, ‘tw1’);
 
stitchclient.executePipeline([
  {
    'service': 'mdb',
    'action': 'find',
    'args': {
      'database': 'people',
      'collection': 'users',
      'query': {'city': 'Boston'}
    }
  }
]);
 
// You can also chain multiple stages
// of service or database actions together. 
// Use ‘let’ to move values from one stage to another. 
stitchclient.executePipeline([
  {
    'service': 'mongodb'
    'action': 'find',
    'args': {
      'database': 'people',
      'collection': 'users',
      'query': {'city': 'Boston'}
    }
  }, {
    'service': 'twilio',
    'action': 'send',
    'let': {'toPhone': '%item.phone'},
    'args': {
      'to': '%%vars.toPhone',
      'from': '+12025550166',
      'body': 'Looks like rain today. Bring an umbrella!'
    }
  }
]) 
 
// Alternatively, you can use the following form:
let result = client.executePipeline([
  mdb.db('people')
    .collection('users')
    .find({ city: 'Boston' }),
  tw
    .let({ toPhone: '%%item.phone' })
    .send(
      '%%vars.toPhone',
      '+12025550166',
      'Looks like rain today. Bring an umbrella!')
]);
 
result.then(function () {
  console.log('pipeline completed execution')
});

// Install with npm:
// npm install mongodb-stitch

// Then simply add the Stitch SDK to your application
const stitch = require('mongodb-stitch');

// 1. Connect to MongoDB
// It’s simple to point Stitch to any MongoDB collection
const client = new stitch.StitchClient('myApp');
const db = client.service('mongodb', 'myMongoDB').db('production');

// Anonymously authenticate, then add and retrieve documents.
client.login()
  .then(function () {
    return db.collection('items')
      .insert({'owner_id': client.authedId(), 'number': 42})
  })
  .then(function () {
    return db.collection('items').find({})
  })
  .then(function (docs) {
    return docs.forEach(function (doc, index) {
      console.log('Document // ', index, ':', JSON.stringify(doc))
    })
  });

// 2. Access Rules
// Define access rules at the document or field level.
// Safe access by default.
// {
//   'owner_id': '%%user.id'
// }


// Create precise, powerful rules by augmenting them with
// built-in expansion functions like ‘%user’
// as well as the MongoDB Aggregation framework.
// {
//   '%or': [
//     { 'owner_id': '%%user.id'},
//     { '%%prev': { '%%exists': false } }
//   ]
// }

// Rules can govern MongoDB or determine whether a service or pipeline is accessible

// 3. Services
// 3rd party services can be defined and accessed directly from the application code.
const slackService = client.service('slack', 'mySlackService');

// Services come with built-in actions that leverage their core features with little code.
slackService.post('stitchChannel', 'user123', 'Hi Slack!')
  .then(function () {
    alert('posted to slack!')
  });

// These actions can also be executed as single stage pipelines
client.executePipeline([
  slackService.post('stitchChannel', 'user123', 'Hi Slack!')
]);

// 4. Multi-stage Pipelines
// executePipeline lets you execute a single database or service actions from your application.
const mdb = client.service('mongodb', 'mdb1');
const tw = client.service('twilio', 'tw1');

stitchclient.executePipeline([
  {
    'service': 'mdb',
    'action': 'find',
    'args': {
      'database': 'people',
      'collection': 'users',
      'query': {'city': 'Boston'}
    }
  }
]);

// You can also chain multiple stages of service or database actions together.
// Use ‘let’ to move values from one stage to another.
stitchclient.executePipeline([
  {
    'service': 'mongodb',
    'action': 'find',
    'args':
      {
        'database': 'people',
        'collection': 'users',
        'query': {'city': 'Boston'}
      }
  },
  {
    'service': 'twilio',
    'action': 'send',
    'let': {'toPhone': '%item.phone'},
    'args':
      {
        'to': '%%vars.toPhone',
        'from': '+12025550166',
        'body': 'Looks like rain today. Bring an umbrella!'
      }
  }
])

// Alternatively, you can use the following form:
let result = client.executePipeline([
  mdb.db('people')
    .collection('users')
    .find({ city: 'Boston' }),
  tw
    .let({ toPhone: '%%item.phone' })
    .send('%%vars.toPhone', '+12025550166', 'Looks like rain today. Bring an umbrella!')
]);

result.then(() => console.log('pipeline completed execution'));

Simple pricing. Pay only for what you use.

25GB
40GB
160GB
1TB
4TB
16TB
Cost Estimate

$0/25GB

25GB free!

Get started free
No credit card required

8 characters minimum One number One letter One special character

Already a MongoDB user? Click here to login.

Frequently Asked Questions

What is MongoDB Stitch?

MongoDB Stitch is a highly configurable, secure, and scalable hosted application backend for MongoDB applications. It gives developers an API to MongoDB, and composability with other services, backed by a robust system for configuring fine-grained data security and privacy. Stitch provides native SDKs for JavaScript, iOS, and Android.

If you want to open up data that you hold in an existing MongoDB Atlas database, then you can define security rules to selectively expose portions of the data to other applications through the Stitch API.

How do I build an app with MongoDB Stitch?

You should use the MongoDB Stitch API to configure the services that you want to use from your application – including MongoDB Atlas. You can optionally also define service pipelines to compose multiple services calls into a single operation. By default, an end-user of your application may only access the data they created – you can add extra security/privacy rules to change that.

Once you have configured the MongoDB Stitch backend, you can access the services directly from your frontend application code using one of Stitch's native SDKs (available for iOS, Android, and JavaScript).

See more frequently asked questions >