Skip to content

UnicodeSnowman/stitch-js-sdk

 
 

Repository files navigation

mongodb-stitch

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

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

Usage

Construct a simple app-wide client:

import { StitchClient } from 'stitch'; let appId = 'sample-app-ovmyj'; let stitchClient = new StitchClient(appId); 

Authenticate anonymously:

stitchClient.anonymousAuth() .then(() => console.log('logged in as: ' + stitchClient.authedId())) .catch(e => console.log('error: ', e)); 

Access MongoDB APIs:

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: let userId = stitchClient.authedId(); 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)); 

Access other services:

// executePipeline takes an array of pipeline stages. stitchClient.executePipeline([ { action: 'literal', args: { items: [ { name: 'hi' }, { name: 'hello' }, { name: 'goodbye' } ] } }, { action: 'match', args: { expression: { name: 'hello' } } } ]) .then(result => console.log('success: ', result)) .catch(e => console.log('error: ', e));; 

About

MongoDB Stitch JavaScript SDK

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%