npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-mongo-database

v1.0.1

Published

MongoDB wrapper for begginers using Mongoose and simple syntax made with JavaScript.

Downloads

9

Readme

easy-mongo-database

MongoDB wrapper for beginners using Mongoose and simple syntax made with JavaScript.


A simple promise-based wrapper made for beginners with focus in Performance and Simplicity.

Inspired in quick.db, Enmap and denky-database


Installation

npm install easy-mongo-database --production

yarn add easy-mongo-database

Support

Create a issue or join my Discord server click here (support only in english and portuguese)


Example

const DatabaseManager = require('easy-mongo-database');
const db = new DatabaseManager('mongodb url here', 'name');

db.on('ready', async () => {
	console.log('Database connected successfully.');
  
  // Create key 'companies' with an array as value.
	await db.set('companies', ['Facebook', 'Apple', 'Amazon', 'Netflix', 'Google'];
  
  // Get the companies list from database
	const companiesList = await db.get('companies');
	console.log(companiesList); // Should return an array.
});

db.on('error', (mongooseError) => {
  console.log('Unexpected error:', mongooseError);
});

db.on('disconnect', (mongooseError) => {
  console.log('Disconnected from the database. Trying to reconnect automatically...');
});

db.connect();

Documentation

  • Database#connection | Mongoose connection object

  • Database#db | Mongoose connection object

  • Database#model | Mongoose model object

  • Database#mongoose | Mongoose model object

  • Database#schema | Mongoose schema object

  • Database#set(key, value) | Create or changes a key with the specified value

    Database.set('website', 'www.github.com/DenkyLabs');
    • Types:
      • Key name: any (*)
      • Value: any (*)
  • Database#get(key) | Returns the value of the specified key

    Database.get('website');
    • Types:
      • Key name: any (*)
      • Returns: undefined or any (*)
  • Database#delete(key) | Delete a key from the database

    Database.delete('website');
    • Types:
      • Key name: any (*)
      • Returns: Object or null
  • Database#exists(key) | Check if a key exists

    Database.exists('website');
    • Types:
      • Key name: any (*)
      • Returns: boolean
  • Database#inc(key) | Increment a number to the key (addition)

    await Database.set('number', 15);
    Database.inc('number', 30) // Sets the value to 45
    • Types:
      • Key name: any (*)
      • Returns: Object or number
  • Database#dec(key) | Decrease a number to the key (addition)

    await Database.set('number', 15);
    Database.dec('number', 10) // Sets the value to 5
    • Types:
      • Key name: any (*)
      • Returns: Object or number
  • Database#deleteAll() | Deletes everything from the database

Database.deleteAll()
  • Types:
    • Returns: Array
  • Database#keyArray() | Get all keys from the database
Database.keyArray();
  • Types:
    • Returns: Array
  • Database#getAll() | Get all objects from the database
Database.getAll();
  • Types:
    • Returns: Array
  • Database#pull(key, value) | Remove an item from an array
await Database.set('companies', ['Google', 'Facebook'])
Database.pull('companies', 'Google'); // ['Facebook']
  • Types:
    • Returns: Object
  • Database#push(key, value) | Add an item from an array
await Database.set('companies', ['Facebook'])
Database.pull('companies', 'Google'); // ['Facebook', 'Google']
  • Types:
    • Returns: Object
  • Database#push(key, value) | Add an item from an array
await Database.set('companies', ['Amazon'])
Database.includes('companies', 'Amazon'); // true
  • Types:
    • Returns: boolean