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

seamless-mongodb-atlas-data-api-sdk

v0.0.4

Published

SDK for the MongoDB Atlas Data API, similar in use to the official MongoDB Node.js driver.

Downloads

4

Readme

Seamless MongoDB Atlas Data API SDK

SDK for the MongoDB Atlas Data API, similar in use to the official MongoDB Node.js driver.

Introduction

This SDK provides a seamless way to communicate with the MongoDB Atlas Data API, especially for projects that already use the official MongoDB Node.js driver or may want to switch at some point. I built it specifically after i had to migrate a project to a serverless platform where connection pooling effectively impossible. Rather than refactor the entire codebase as other SDK's would require me to do, I in this SDK attempted to match the interfaces of the official nodejs driver as much as possible, and in specifically also emulates the FindCursor, so that my original codebase would remain intact. Should pricing, traffic, etc. make another choice preferable later on, I can now also easily switch back.

Disclaimer: This is a work in progress with still plenty to do. I've added the most important methods and features based on my own requirements. Not every feature of the official driver is available (yet) and also the Atlas Data Api doesn't support every feature a regular connection would. I'll add more as I come to need it or as features get requested. I'm also open to pull requests should you wish to contribute.

Installation

npm install seamless-mongodb-atlas-data-api-sdk

Usage

Initialization

import { MongoClient } from "seamless-mongodb-atlas-data-api-sdk";

const client = new MongoClient({
	instance: "Cluster0",
	endpoint: "https://REGION.PROVIDER.data.mongodb-api.com/app/data-ovfml/endpoint/data/v1",
	apiKey: "your-API-key"
});

const db = client.db("your-db-name");
const collection = db.collection("your-collection-name");

CRUD Operations

Insert a Document

Use the insertMany method to add three documents to the documents collection.

const insertResult = await collection.insertMany([{ a: 1 }, { a: 2 }, { a: 3 }]);
console.log("Inserted documents =>", insertResult);

The insertMany command returns an object with information about the insert operations.

Find All Documents

Add a query that returns all the documents.

const findResult = await collection.find({}).toArray();
console.log("Found documents =>", findResult);

This query returns all the documents in the documents collection. If you add this below the insertMany example you'll see the document's you've inserted.

Find Documents with a Query Filter

Add a query filter to find only documents which meet the query criteria.

const filteredDocs = await collection.find({ a: 3 }).toArray();
console.log("Found documents filtered by { a: 3 } =>", filteredDocs);

Only the documents which match 'a' : 3 should be returned.

Update a document

The following operation updates a document in the documents collection.

const updateResult = await collection.updateOne({ a: 3 }, { $set: { b: 1 } });
console.log("Updated documents =>", updateResult);

The method updates the first document where the field a is equal to 3 by adding a new field b to the document set to 1. updateResult contains information about whether there was a matching document to update or not.

Remove a document

Remove the document where the field a is equal to 3.

const deleteResult = await collection.deleteMany({ a: 3 });
console.log("Deleted documents =>", deleteResult);

About the Cursor

At a glance, the Cursor in this SDK appears to function similarly to the one in the native MongoDB Node.js driver. It offers many of the same methods and can be used in a way that feels almost identical. This is by design, to ensure developers have a hopefully seamless experience transitioning or integrating this SDK into existing projects.

Internally it maintains an array with documents returned. If no limit was given it will default to a certain value and re-fetch more data as you iterate through it.

Contributing

If you'd like to contribute feel free to send a message? Create a pull request.

License

This project is licensed under a MIT license. See the LICENSE file for exact details.