Skip to content

modern, TypeScript-based SDK designed to simplify and supercharge your interaction with MongoDB Atlas

License

Notifications You must be signed in to change notification settings

shivarm/mongodb-atlas-sdk

Repository files navigation

Node.js CI npm version GitHub issues

mongodb-atlas-sdk is a modern, TypeScript-based SDK designed to simplify and supercharge your interaction with MongoDB Atlas. Built with scalability, ease of use, and extensibility in mind, mongodb-atlas-sdk is the perfect solution for developers who need a flexible and robust tool to handle their database operations.

Why mongodb-atlas-sdk?

Unlike other MongoDB SDKs, MongoKit focuses on developer productivity, scalability, and modern application needs. Whether you’re building a high-performance REST API, a real-time app, or a distributed system, mongodb-atlas-sdk is here to empower your database operations.

Key Features

  • Easy MongoDB Atlas Connection: Establish secure and reliable connections with MongoDB Atlas using simple configuration.
  • Schema Validation: Ensure data integrity with JSON schema validation powered by Zod.
  • TypeScript-First: Enjoy fully typed APIs for improved developer experience and better code quality.

Installation

Install mongokit using npm, pnpm or yarn:

npm install mongodb-atlas-sdk

pnpm add mongodb-atlas-sdk

yarn add mongodb-atlas-sdk

Important

You can check node/express example App

Usage

import { MongoDbConnection } from 'mongodb-atlas-sdk';

const mongoConnect = new MongoDbConnection('your-mongodb-uri');

async function main() {
  await mongoConnect.connect();

  const db = mongoConnect.getDatabase('my-database');
  console.log('Database connected:', db.databaseName);

  await mongoConnect.disconnect();
}

main().catch(console.error);

Methods

  • connect(): Promise<void> Connects to the MongoDB server.

  • getDatabase(name: string): Db Returns a database instance for the given name.

  • disconnect(): Promise<void> Disconnects from the MongoDB server.

Custom Schema

You can create custom schemas with Zod.

import { z, SchemaValidator } from 'mongodb-atlas-sdk';

const productSchema = z.object({
  name: z.string().min(1, 'Product name is required'),
  price: z.number().min(0, 'Price must be non-negative'),
});

const productValidator = new SchemaValidator(productSchema);

const product = { name: 'Laptop', price: 999 };

try {
  const validatedProduct = productValidator.validate(product);
  console.log('Validated product:', validatedProduct);
} catch (error) {
  console.error('Validation failed:', error.message);
}

Development

See our Contributing Guide.

Support

  • Give a ⭐️ if this project helped you!
  • You can also sponsor me on Github

About

modern, TypeScript-based SDK designed to simplify and supercharge your interaction with MongoDB Atlas

Resources

License

Stars

Watchers

Forks

Packages

No packages published