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-rest-client

v1.1.2

Published

[![npm version](https://img.shields.io/npm/v/mongo-rest-client?logo=npm&logoColor=fff)](https://www.npmjs.com/package/mongo-rest-client) ![NPM Downloads](https://img.shields.io/npm/dw/mongo-rest-client) ![npm bundle size](https://img.shields.io/bundlephob

Downloads

3,242

Readme

Mongo-Rest-Client

npm version NPM Downloads npm bundle size npm package minimized gzipped size NPM License

A MongoDB connector that uses fetch to communicate with DB. Fully type safe rest api based connector. Runs everywhere from NodeJS to Edge runtime.

Features

  • Fully Type-Safe Schema based connector
    • Instead of calling db.collection("users").insertOne(...), you call db.users.insertOne(UserObject)
  • No Crypto Module requried (Can run in both NodeJS and Edge Network (like Vercel))
  • Framework agnostic - Run anywhere that runs JS
  • Uses fetch api under-the-hood. So take advantage of caching in framework like NextJS

Supported Functions

  • [x] Find one document (findOne)
  • [x] Find many documents (findMany)
  • [x] Insert One Document (insertOne)
  • [x] Insert Documents (insertMany)
  • [x] Update One Document (updateOne)
  • [x] Update Documents (updateMany)
  • [x] Delete One Document (deleteOne)
  • [x] Delete Documents (deleteMany)
  • [ ] Aggregate Documents (todo)

Usage

Create a db by passing baseUrl (of data api), apiKey, dbName, and a schemaBuilder (a function that takes db instance and return an object of db.collection (add type to this object to take full advantage of it))

// db.ts file
import { MongoDB } from "mongo-rest-client";
export const db = MongoDB.connect({
  baseUrl: process.env.mongoDBUrl,
  apiKey: process.env.mongoDBApiKey,
  dbName: process.env.mongoDBName,
  schemaBuilder: (db) => ({
    users: db.collection<User>("users"),
    posts: db.collection<Post>("posts"),
  }),
});

// use it anywhere
await db.users.insertOne(...) // typesafe
await db.users.updateOne(...) // typesafe filter and data
const user = db.users.findOne({
    postID: "something..." // Compile-time ERROR: postID does not exists in User
}) // typesafe Filter
const user = db.users.findOne({
  _id: {
    $oid: "valid mongo db id"
  } // MongoDB requires an ObjectID. Dont worry its typesafe
}) // typesafe Filter

Limitations

mongo-rest-client uses the Data API from MongoDB. Hence, it has all the limitations of DataAPI like transactions. Read more here: https://www.mongodb.com/docs/atlas/app-services/data-api/openapi/