New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongodb-stitch

Package Overview
Dependencies
Maintainers
7
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-stitch

[![Join the chat at https://gitter.im/mongodb/stitch](https://badges.gitter.im/mongodb/stitch.svg)](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

  • 3.0.2
  • npm
  • Socket score

Version published
Weekly downloads
70
decreased by-52.05%
Maintainers
7
Weekly downloads
 
Created
Source

mongodb-stitch

Join the chat at https://gitter.im/mongodb/stitch

MongoDB Stitch Users - Google Group

MongoDB Stitch Announcements - Google Group

The original source is located in src/. To transpile to pure JS, run npm run build which places the output into dist/.

Documentation

Usage

Construct a simple app-wide client
import { StitchClientFactory } from 'mongodb-stitch';
let appId = 'sample-app-ovmyj';
let stitchClientPromise = StitchClientFactory.create(appId);

The StitchClient only needs to be resolved once from StitchClientFactory.create() and it can be used for the lifetime of an application.

Authenticate anonymously
stitchClientPromise.then(stitchClient => stitchClient.login())
  .then(() => console.log('logged in as: ' + stitchClient.authedId()))
  .catch(e => console.log('error: ', e));
Access MongoDB APIs
stitchClientPromise.then(stitchClient => {
  let db = stitchClient.service('mongodb', 'mongodb1').db('app-ovmyj'); // mdb1 is the name of the mongodb service registered with the app.
  let itemsCollection = db.collection('items');

  // CRUD operations:
  const userId = stitchClient.authedId();
  return itemsCollection.insertMany(
    [ 
      { owner_id: userId, x: 'item1' }, 
      { owner_id: userId, x: 'item2' }, 
      { owner_id: userId, x: 'item3' } 
    ]
  );
}).then(result => console.log('success: ', result))
  .catch(e => console.log('error: ', e));
Execute a function
stitchClientPromise.then(stitchClient => 
  stitchClient.executeFunction('myFunc', 1, 'arg2', {arg3: true})
).then(result => console.log('success: ', result))
  .catch(e => console.log('error: ', e));
Execute a service function
stitchClientPromise.then(stitchClient =>
  stitchClient.executeServiceFunction('http1', 'get', {url: 'https://domain.org'})
).then(result => console.log('success: ', result))
  .catch(e => console.log('error: ', e));

Building

If this library is being used to compile to a web format, you must compile some of its dependencies to ES5. The following dependencies use ES6 and are not compiled to ES5:

Building for the Web with webpack

In order to compile the pure ES6 dependencies of this library to ES5, babel-loader can be used. See the section on usage (https://github.com/babel/babel-loader#usage) for how to load specific files. For this library, you must include the above dependencies in your node_modules for compilation to ES5.

The following rule loads any .js or .jsx file unless it's within node_modules (excluding the above dependencies):

{
  test: /\.jsx?$/,
  exclude: /node_modules\/(?!(mongodb-extjson|bson))/,
  loaders: ['babel-loader']
}

FAQs

Package last updated on 13 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc