HomeLearnHow-toWorking with MongoDB Stitch Through the mongo Shell - MongoDB Wire Protocol Support

Working with MongoDB Stitch Through the mongo Shell - MongoDB Wire Protocol Support

Updated: Mar 10, 2022 |

Published: Sep 27, 2018

  • Realm
  • Atlas
  • JavaScript
  • ...

By Andrew Morgan

Rate this article

Please note: This article discusses Stitch. Stitch is now MongoDB Realm. All the same features and functionality, now with a new name. Learn more here. We will be updating this article in due course.

The Stitch SDK is the best way to access MongoDB Stitch from your frontend application code - getting to your data and accessing your Stitch Services and Functions becomes child's' play.

However, those already using MongoDB may have existing backend code and tools that work with MongoDB. MongoDB Stitch now supports the MongoDB wire protocol - meaning that you can continue to work with your favorite tools (including the mongo shell) and drivers while benefiting from Stitch's quick and simple data access control and hosted JavaScript functions.

After enabling connection string access, connecting to your Stitch app from the mongo shell is business as usual - just use the connection string you're shown in the Stitch UI:

1mongo "mongodb://andrewjamXXXXX%40gmail.com:gXXXX@stitch.mongodb.com:27020\ /?authMechanism=PLAIN&authSource=%24external&ssl=true&\ appName=imported_trackme-xxxxz:mongodb-atlas:local-userpass" --norc

Once connected, adding a document through Stitch should feel very familiar:

2 owner_id: "5bacd4e7698a67f72dfdb44c",
3 author: "Andrew Morgan",
4 comment: "Stitch wire protocol support rocks!"

MongoDB Stitch wire protocol
MongoDB Stitch wire protocol

However, Stitch is about more than accessing MongoDB data. I've created a (stupidly) simple Stitch (morning) Function to show how you can test your Stitch app:

1exports = function(name){
2 return {message: "Good Morning " + name + " from "
3 + context.user.data.email};

From the mongo shell, I can now test that function:

1db.runCommand({ callFunction: "morning", arguments: ["Billy"] })
3 "ok" : 1,
4 "response" : {
5 "message" : "Good Morning Billy from greetings@clusterdb.com"
6 }

Creating your first Stitch app? Start with one of the Stitch tutorials.

Want to learn more about MongoDB Stitch? Read the white paper.

Rate this article
MongoDB logo
© 2021 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.