quick-mongo-super
TypeScript icon, indicating that this package has built-in type declarations

1.0.12 • Public • Published

Quick Mongo Super

Downloads Stable Version

Quick Mongo Super is a light-weight and easy-to-use Node.js module written in TypeScript to work with MongoDB.

| Why?

  • TypeScript Support 📘
  • 100% Promise-based 📜
  • Flexible ⚙️
  • Easy to use 👍
  • Beginner Friendly 😄

📂 | Installation

Note: Node.js 14.0.0 or newer is required.

npm i quick-mongo-super
yarn add quick-mongo-super
pnpm add quick-mongo-super

Examples

Initialize the module

import QuickMongo from '../src/index'

const db = new QuickMongo({
    connectionURI: 'your mongodb connection URI here', // MongoDB connection URI to connect to the database.
    dbName: 'db', // MongoDB database name to use.
    collectionName: 'database' // MongoDB collection name to use.

    mongoClientOptions: {
      // MongoDB client options here.
    }
})

Example Usage

    // checking for updates (optional)
    const versionData = await db.checkUpdates()
    console.log(versionData)

    // output:
    // { 
    //   updated: true, 
    //   installedVersion: '1.0.11', 
    //   packageVersion: '1.0.11' 
    // }


    // connect to database
    console.log('Connecting to database...')
    await db.connect()

    console.log('Connected to database!')


    // SETTING DATA

    // setting object in database
    await db.set<Omit<AccountData['auth'], 'password'>>('accountData.auth', {
      username: 'shadowplay'
    })

    // setting a property in object
    await db.set<string>('accountData.auth.password', 'test123')

    // accountData in database:
    // {
    //     auth: {
    //         username: 'shadowplay',
    //         password: 'test123'
    //     }
    // }


    // ARRAYS

    // pushing into an array
    await db.push<string>('accountData.roles', 'admin') // accountData.roles in database: ['admin']

    // changing the array element in database
    await db.changeElement<string>('accountData.roles', 0, 'user') // accountData.roles in database: ['user']

    // changing the array element in database
    await db.removeElement('accountData.roles', 0) // accountData.roles in database: []


    // NUMBERS

    // adding to a number
    await db.add('accountData.balance', 100)

    // subtracting from a number
    await db.subtract('accountData.balance', 50)
  
    // deleting properties
    await db.delete('accountData.roles')


    // GETTING DATA

    await db.fetch<AccountData>('accountData')
    // {
    //     auth: {
    //         username: 'shadowplay',
    //         password: 'test123'
    //     },
    //     roles: [],
    //     balance: 50
    // }


    // disconnect from database
    await db.disconnect()

See the full examples for JavaScript and TypeScript here.

See the full changelog here.

🤔 | Help

If you don't understand something or you're experiencing problems, feel free to join our Support Server.

🕘 | My Other Modules

| Useful Links


If you don't understand something or you are experiencing problems, feel free to join our Support Server.
Module Created by ShadowPlay.

❤️ Thanks for choosing Quick Mongo Super ❤️

Install

npm i quick-mongo-super

DownloadsWeekly Downloads

126,737

Version

1.0.12

License

MIT

Unpacked Size

58.5 kB

Total Files

21

Last publish

Collaborators

  • shadowplay