npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongo-fetch-api

v0.2.0

Published

Self-hosted Mongo Data API

Downloads

5

Readme

Mongo Fetch API - Self-hosted Data API

An almost 1-to-1 mapping of the MongoDB Atlas Data API to a self-hosted server. This allows you to run your own data API in whatever cloud provider you wish, fly.io, DigitalOcean, etc.

You can connect and use this API as if it were native MongoDB by using our Data API driver. This allows you to access MongoDB data from edge-compute services like Cloudflare Workers.

Why?

MongoDB Atlas Data API is a great service, but because its based on AWS Lambda, its very slow. This is because it has to spin up a new instance of the lambda function for every request. This is fine for small amounts of data, but for larger amounts of data, it can take a long time to return the data.

This project aims to solve that problem by running the API on a server, and using MongoDB's native driver to connect to the database. This means that the server can keep a connection open to the database, and the data can be streamed directly to the client. At the cost of always running. However, this is a small price to pay for the performance gains.

Installing and running

Import

import { createService } from '@drivly/mongo-fetch-api'

const main = async () => {
  await createService(
    3000, // port
    {
      readOnly: 'readonlykey',
      readWrite: 'secret'
    },
    {
      cluster1: 'mongodb://localhost:27017',
      cluster2: 'mongodb://localhost:27018'
    }
  )
}

main()

Node

git clone https://github.com/drivly/mongo-fetch-api.git

cd mongo-fetch-api

npm install

npm run serve

Docker

git clone https://github.com/drivly/mongo-fetch-api.git

cd mongo-fetch-api

docker build -t mongo-fetch-api .

docker run -p 3000:3000 -e READ_ONLY_KEY=readonlykey -e READ_WRITE_KEY=secret -e MONGO_URI_CLUSTER1=mongodb://localhost:27017 -e MONGO_URI_CLUSTER2=mongodb://localhost:27018 mongo-fetch-api

Environment variables

READ_ONLY_KEY - The key used to authenticate read-only requests, will refuse any action other than find.

READ_WRITE_KEY - The key used to authenticate read-write requests.

PORT - The port to run the server on.

MONGO_URI_${clusterName} - The URL to connect to the MongoDB instance. Replace ${clusterName} with the name of the cluster. This will be used as the "dataSource" field in the request.

e.g. MONGO_URI_CLUSTER1=mongodb://localhost:27017

means you can access it via:

POST /api/v1/action/findOne?dataSource=CLUSTER1&database=...&collection=...