Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongodb-queryrunner

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-queryrunner

MongoManager is a versatile Node.js library for MongoDB database operations, offering simplified querying and efficient data manipulation. With intuitive methods and seamless integration, MongoManager streamlines database interactions, allowing developers

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

MongoDB Manager

MongoDB Manager is a lightweight JavaScript library designed to simplify interactions with MongoDB databases. It provides a high-level abstraction for common database operations, making it easier for developers to work with MongoDB in their Node.js applications.

Features

  • Simplified API: Abstracts away the complexity of MongoDB operations, providing a straightforward interface for database interactions.
  • Error Handling: Robust error handling mechanisms ensure that errors are caught and handled gracefully, providing informative error messages for debugging.
  • Lazy Connection: Establishes connections to the MongoDB server only when required, optimizing resource usage.
  • Parameter Validation: Validates input parameters to ensure data integrity and prevent common errors.
  • Consistent Result Formatting: Ensures that query results are always returned as arrays, simplifying downstream data processing.

Installation

Install MongoDB Manager via npm:

npm install mongodb-queryrunner

Usage

const MongoManager = require('mongodb-queryrunner');



(async function () {
    const mongoManager = new MongoManager(process.env.DB_URL, process.env.DB_NAME);
    try {
        // Initialize MongoDB Manager with MongoDB URL and database name

        // Build query parameters
        let params = mongoManager.queryParamsBuilder("app_user_data", "find", { id: "1234" });

        // Execute the query
        let data = await mongoManager.queryRunner(params);

        // Output the result
        console.log('Data:', data);
    } catch (error) {
        console.error(error.message);
    } finally {
        // Close the MongoDB connection
        await mongoManager.db_close();
    }
})();


Aggregation Example

const  MongoManager  = require('mongodb-queryrunner');


(async function () {
    try {
        // Initialize MongoDB Manager with MongoDB URL and database name
        const mongoManager = new MongoManager(process.env.DB_URL, process.env.DB_NAME);
        // Build query parameters for aggregation
        let params = mongoManager.queryParamsBuilder("app_user_data", "aggregate", [{$match:{ id: "1234" }}]); // insertmany or aggregation must be an array....

        // Execute the aggregation query
        let data = await mongoManager.queryRunner(params);

        // Output the result
        console.log('Aggregation Result:', data);
    } catch (error) {
        console.error(error.message);
    } finally {
        // Close the MongoDB connection
        await mongoManager.db_close();
    }
})();

Keywords

FAQs

Package last updated on 06 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc