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

@gmmurray/mongodb-atlas-data-api

v1.1.0

Published

api client wrapper around the mongodb atlas data api

Downloads

8

Readme

npm version license types commits

@gmmurray/mongodb-atlas-data-api

A client library for interacting with the Atlas Data API.

Prerequisites

This library requires the following dependencies:

  • axios for making HTTP requests.
$ npm install axios

Table of Contents

Getting Started

These instructions will help you get started with using the Atlas Data API Client in your project.

Installation

To install the library, run the following command:

$ npm install atlas-data-api-client

Alternatively, you can use Yarn:

$ yarn add atlas-data-api-client

Usage

In these examples we use a made up customer interface:

interface Customer {
  id: string;
  name: string;
  age: number;
}

Creating the Client

import AtlasDataApiClient, {
  AtlasDataApiClientOptions,
} from '@gmmurray/atlas-data-api-client';

const options: AtlasDataApiClientOptions = {
  apiKey: 'YOUR_API_KEY',
  dataApiUrlEndpoint: 'your-app-url-endpoint',
  defaultDataSource: 'your-default-data-source',
  defaultDatabase: 'your-default-database',
};

const apiClient = new AtlasDataApiClient(options);

Find One Document

const request: FindOneDocumentRequest<Customer> = {
  collection: 'your-collection',
  filter: { name: 'John Doe' },
};

const response: FindOneApiResponse<Customer> = await apiClient.findOneDocument(
  request,
);

console.log(response);

Find Many Documents

const request: FindManyDocumentsRequest<Customer> = {
  collection: 'your-collection',
  filter: { age: { $gte: 18 } },
  sort: { name: 1 },
  pageSize: 10,
  pageNumber: 1,
};

const response: FindManyApiResponse<Customer> = await apiClient.findDocuments(
  request,
);

console.log(response);

Insert One Document

const request: InsertOneDocumentRequest<Customer> = {
  collection: 'your-collection',
  document: { name: 'John Doe', age: 25 },
};

const response: InsertOneApiResponse = await apiClient.insertOneDocument(
  request,
);

console.log(response);

Insert Many Documents

const request: InsertManyDocumentsRequest<Customer> = {
  collection: 'your-collection',
  documents: [
    { name: 'John Doe', age: 25 },
    { name: 'Jane Smith', age: 30 },
  ],
};

const response: InsertManyApiResponse = await apiClient.insertManyDocuments(
  request,
);

console.log(response);

Update One Document

const request: UpdateOneDocumentRequest<Customer> = {
  collection: 'your-collection',
  filter: { id: '123' },
  update: { name: 'John Doe', age: 26 },
  upsert: true,
};

const response: UpdateOneApiResponse = await apiClient.updateOneDocument(
  request,
);

console.log(response);

Update Many Documents

const request: UpdateManyDocumentsRequest<Customer> = {
  collection: 'your-collection',
  filter: { age: { $gte: 18 } },
  update: { status: 'active' },
  upsert: true,
};

const response: UpdateManyApiResponse = await apiClient.updateManyDocuments(
  request,
);

console.log(response);

Replace One Document

const request: ReplaceOneDocumentRequest<Customer> = {
  collection: 'your-collection',
  filter: { id: '123' },
  replacement: { id: '123', name: 'John Doe', age: 27 },
  upsert: true,
};

const response: ReplaceOneApiResponse = await apiClient.replaceOneDocument(
  request,
);

console.log(response);

Delete One Document

const request: DeleteOneDocumentRequest<Customer> = {
  collection: 'your-collection',
  filter: { id: '123' },
};

const response: DeleteOneApiResponse = await apiClient.deleteOneDocument(
  request,
);

console.log(response);

Delete Many Documents

const request: DeleteManyDocumentsRequest<Customer> = {
  collection: 'your-collection',
  filter: { age: { $gte: 18 } },
};

const response: DeleteManyApiResponse = await apiClient.deleteManyDocuments(
  request,
);

console.log(response);

Aggregate Documents

const request: AggregateDocumentsRequest = {
  collection: 'your-collection',
  pipeline: [
    { $match: { age: { $gte: 18 } } },
    { $group: { _id: '$gender', count: { $sum: 1 } } },
  ],
};

const response: AggregateApiResponse = await apiClient.aggregateDocuments(
  request,
);

console.log(response);

API Reference

| Method | Description | | ------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | findOneDocument(request: FindOneDocumentRequest): Promise<FindOneApiResponse> | Finds a single document in the specified collection. | | findDocuments(request: FindManyDocumentsRequest): Promise<FindManyApiResponse> | Finds multiple documents in the specified collection. | | insertOneDocument(request: InsertOneDocumentRequest): Promise | Inserts a single document into the specified collection. | | insertManyDocuments(request: InsertManyDocumentsRequest): Promise | Inserts multiple documents into the specified collection. | | updateOneDocument(request: UpdateOneDocumentRequest): Promise | Updates a single document in the specified collection. | | updateManyDocuments(request: UpdateManyDocumentsRequest): Promise | Updates multiple documents in the specified collection. | | replaceOneDocument(request: ReplaceOneDocumentRequest): Promise | Replaces a single document in the specified collection. | | deleteOneDocument(request: DeleteOneDocumentRequest): Promise | Deletes a single document from the specified collection. | | deleteManyDocuments(request: DeleteManyDocumentsRequest): Promise | Deletes multiple documents from the specified collection. | | aggregateDocuments(request: AggregateDocumentsRequest): Promise | Performs an aggregation on the specified collection. |

For more details on each method and their request/response types, please refer to the source code documentation.

Credits