JSPM

@ph4ntomiki/mongodb-data-api-client

0.0.7
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q16111F
  • License ISC

MongoDB Data API Client

Package Exports

  • @ph4ntomiki/mongodb-data-api-client
  • @ph4ntomiki/mongodb-data-api-client/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ph4ntomiki/mongodb-data-api-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

The package that uses MongoDB Atlas Data API to access your data

First you need to get an API key and App ID for the service, explained how here.

After that import/require the package and use it like this:

const MongoClient = require('@ph4ntomiki/mongodb-data-api-client');
const client = MongoClient('app_id', 'api_key', 'clusterName'); //cluster defaults to 'Cluster0'
const db = client.db('dbName');
const collection = db.collection('collectionName');

const results = await collection.find({title: /a/i});

You can also create client with custom fetch implementation, like for ex. for Cloudflare Workers like this:

const client = MongoClient('app_id', 'api_key', 'clusterName', {'fetch': fetch.bind(self)});

Or if you want default clusterName you can pass undefined or null at that place.