Skip to content

arunv11u/common.mongodb-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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.

About

This repository contains wrapper for MongoDB module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors