Options
All
  • Public
  • Public/Protected
  • All
Menu

RemoteMongoClient

The RemoteMongoClient can be used to get database and collection objects for interacting with MongoDB data via the Stitch MongoDB service.

Service clients are created with StitchAppClient.getServiceClient by passing RemoteMongoClient.factory and the "Stitch Service Name" found under Clusters in the Stitch control panel ("mongodb-atlas" by default).

Once the RemoteMongoClient is instantiated, you can use the db method to access a RemoteMongoDatabase. A RemoteMongoDatabase will then provide access to a RemoteMongoCollection, where you can read and write data.

Note: The client needs to log in (at least anonymously) to use the database. See StitchAuth.

Example

const stitchAppClient = Stitch.defaultAppClient

// Get the RemoteMongoClient via the service client interface
const mongoClient = stitchAppClient.getServiceClient(RemoteMongoClient.factory, 'mongodb-atlas')

// Log in to access the database. Anonymous Authentication is enabled from the Stitch UI.
stitchAppClient.auth
  .loginWithCredential(new AnonymousCredential())
  .then(() => {
    // Retrieve a database object
    const db = mongoClient.db('video')

    // Retrieve the collection in the database
    const movieDetails = db.collection('movieDetails')

    // Find 10 documents and log them to console.
    movieDetails.find({}, {limit: 10})
      .toArray()
      .then(results => console.log('Results:', results))
      .catch(console.error)
  })
  .catch(console.error)

See Also

Index

Variables

Methods

Variables

Const factory

factory: NamedServiceClientFactory<RemoteMongoClient> = new classimplements NamedServiceClientFactory<RemoteMongoClient> {public getNamedClient(service: CoreStitchServiceClient,client: StitchAppClientInfo): RemoteMongoClient {return new RemoteMongoClientImpl(new CoreRemoteMongoClientImpl(service));}}()

Methods

db

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc