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

ez.database

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ez.database

Easy to use and lightweight MongoDB Wrapper Database for beginners.

  • 1.0.7
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Ez.Database

Ez.Database is an extremely light, and straightforward MongoDB Database wrapper.

Note: The package is still in development, and is not completely ready to use yet.

Ez.Database was created to make the process of using MongoDB very easy and quick, so that even a complete beginner could understand how a Database works, and get started using one.

Why choose Ez.Database?

Beginner Friendly - It's very easy for a beginner to use the db, and it only takes a few seconds to get setup, and connect to MongoDB.

Light - Ez.Database is extremely light, comprised with only a few files, which makes it very fast to run.

Simplifies Schemas - The package simplifies Schemas, and instead uses the set, has, and get method, to simplify the process, making it easy to set, check, and get data.


Installation

After you have initialized node, run this command:

npm install ez.database

API Documentation

With our step by step Guide, you can get started in seconds!
For the full API documentation, please visit our website, at WEBSITENAME.

Note: Since this is meant for absolute beginners, the guide will have everything from setting up MongoDB, getting your connection string, to connecting to the Database and using the methods. If you are not an absolute beginner, feel free to skip to certain parts in the guide.

Setup

To get the project started, run the command npm init -y, to initalize your project as node:

npm init -y

After that, please run the installation command for this Database.


Setting up MongoDB

Creating An Account

To setup a Database, please visit MongoDB's Website. Next, click login, and from there, click sign up. You can either create an account, or sign up with Google.


Installing MongoDB Compass

Next, we're going to install MongoDB Compass. Compass is good for visualising and understanding data, and query syntax. It also makes managing your Databases and Collections easier. To install it, visit the Compass Download Page, and click download.


Creating a Cluster + Connecting to Cluster

When Compass is finished installing, open it up. You should see a screen where you need to paste your connection string.

To get the connection string, we need to make a Cluster, which we are going to connect to in Compass. Please go to the MongoDB website.

There should be a screen which says Clusters, Create a New Cluster, and many more things. Click on the Create a New Cluster button. You can specify your Cloud Provider and Region, but for free access, select a region with the symbol FREE TIER AVAILABLE, and ideally one close to where you are, for better connection. You can specify your Cluster name, then hit Create Cluster.

It should take a few seconds/minutes to create. Meanwhile, we're going to create a user, so we can authenticate into our Cluster.

Click the Database Access button. There, add a new Database User, and make the user's name, and password, and click Add User.

Once your Cluster is finished being made, click the Connect button, and select Connect using MongoDB Compass. There, you will see your connection string. Copy it. Finally, go back to Compass, and paste your connection string. You will need to replace the password text, with your user password.

Note: You can only have one free Cluster. If you would like to create an additional Cluster, you have to pay a small fee to MongoDB.


Creating a Database and Collection

Now, you need to create a Database. In Compass, click the Create Database button, and specify your Database and Collection name. Next, click Create Collection, and specify your collection name.

You are now all set up with MongoDB! Let's see how to use Ez.Database!


Using Ez.Database

Connecting to MongoDB with Ez.Database

Getting started using Ez.Database is very easy, and takes a few seconds.

In order to connect to MongoDB, we need to make a variable for our connection string. Since the connection string is a sensitive piece of information, we are going to store it in a seperate JSON file. Name that file ConnectionString.json.

Make an object called MongoConnectionString, which will hold the string. Paste the following code into that file:

{
    "MongoConnectionString": "yourconnectionstring"
}

You'd use the same connection string you used to connect in MongoDB Compass.

Now, make a file called db.js. Here, paste the following code:

const { MongoConnectionString } = require('./ConnectionString.json')

const EzDatabase = require('ez.database')
const db = new EzDatabase()

db.connect(MongoConnectionString,
    console.log('Connected to Database')
)

How does this work? First, the MongoConnectionString object is required, from our JSON file. The technique used is called Object Destructuring.

Then, we require the actual Ez.Database module. After that, we make a variable called db, which is an instance of the Ez.Database class.

Next, we use the connect method, to connect to our MongoDB database, while passing in our connection string to do so. We also log the message we want when we have connected to MongoDB.


Storing, Getting, and Checking Data

Ez.Database simplifies the process of creating Schemas, and instead just uses the set, get, and has methods. Add the follow code to your file:

const { MongoConnectionString } = require('./ConnectionString.json')

const EzDatabase = require('ez.database')
const db = new EzDatabase()

db.connect(MongoConnectionString,
    console.log('Connected to Database')
)

//What you're adding
db.set('Dataset', {data: object})
db.get(Dataset.data)
db.has(Dataset.Data)

db.save()

The set method sets Data, and you can set your Dataset name. It also takes 2 parameters. The first one is the actual Dataset name, and the second is the property and object.

The get method gets Data, from a specific Dataset, and access the property and object in that Dataset.

The has method returns either true, or false. It's used for checking if a certain Dataset has some data.

Finally, the save method saves all of your data, to the Database.

Dependencies

Ez.Database has two Dependencies:

  1. Mongoose
  2. MongoDB

Update Log

Future updates will be written here.


Please share the package with your friends, and hope you found Ez.Database useful!

Keywords

FAQs

Package last updated on 11 Sep 2020

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