@arunvaradharajalu/common.mongodb-api
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

@arunvaradharajalu/common.mongodb-api

npm version GitHub issues GitHub license

This package provides a wrapper for the MongoDB module, simplifying the usage of MongoDB operations within your Node.js applications.

Installation

You can install this package using npm:

npm install @arunvaradharajalu/common.mongodb-api

Usage

Setting Up the MongoDB Connection

First, initialize and configure the MongoDB connection:

import { mongoDBConnect } from "@arunvaradharajalu/common.mongodb-api";

// Set connection details
mongoDBConnect.url = "your-mongodb-url";
mongoDBConnect.dbName = "your-database-name";
mongoDBConnect.username = "your-username";
mongoDBConnect.password = "your-password";

// Initialize and connect
mongoDBConnect.init();
await mongoDBConnect.connect();

Using the MongoDB Repository

Once the connection is established, you can use the MongoDBRepositoryImpl class to perform CRUD operations.

import { MongoDBRepositoryImpl } from "@arunvaradharajalu/common.mongodb-api";

const db = mongoDBConnect.dbContext;
const repository = new MongoDBRepositoryImpl(mongoDBConnect, db);

// Example: Insert a document
await repository.add("your-collection-name", { key: "value" });

// Example: Find a document by ID
const document = await repository.get("your-collection-name", "document-id");
console.log(document);

// Example: Update a document
await repository.update("your-collection-name", { key: "value" }, { $set: { key: "new-value" } });

// Example: Delete a document
await repository.remove("your-collection-name", { key: "value" });

Features

  • Simplified MongoDB connection handling
  • CRUD operations for MongoDB collections
  • Transaction support
  • Aggregation operations

Running Tests

To run the tests, use:

npm test

The test results will be generated in an HTML report with the title "MongoDB API Test Report".

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for bug fixes, improvements, or new features.

Author

Arun Varadharajalu

License

This project is licensed under the ISC License.

Readme

Keywords

Package Sidebar

Install

npm i @arunvaradharajalu/common.mongodb-api

Weekly Downloads

8

Version

1.1.1

License

ISC

Unpacked Size

51.2 kB

Total Files

31

Last publish

Collaborators

  • arunvaradharajalu