ez.database
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "ez.database", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Easy to use and lightweight MongoDB Wrapper Database for beginners.", | ||
@@ -12,12 +12,18 @@ "main": "src/Database/Database.js", | ||
"license": "", | ||
"devDependencies": { | ||
"@types/mongoose": "^5.7.36", | ||
"@types/node": "^14.6.4", | ||
"nodemon": "^2.0.4", | ||
"typescript": "^4.0.2" | ||
}, | ||
"devDependencies": {}, | ||
"dependencies": { | ||
"mongodb": "^3.6 x.1", | ||
"mongodb": "^3.6.2", | ||
"mongoose": "^5.10.4" | ||
} | ||
}, | ||
"keywords": [ | ||
"mongodb", | ||
"mongoose", | ||
"db", | ||
"database", | ||
"mongodb wrapper", | ||
"db wrapper", | ||
"ez.db", | ||
"ez.database", | ||
"easy database" | ||
] | ||
} |
159
README.md
@@ -1,1 +0,158 @@ | ||
# Ez.Database | ||
# Ez.Database | ||
**Ez.Database** is an extremely light, and straightforward MongoDB Database wrapper. | ||
--- | ||
**Ez.Database** was created to make the process of using MongoDB very easily, and quickly, 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 our db, and it only takes a few seconds to get setup, and connect to MongoDB. | ||
<br /> | ||
**Light -** Ez.Database is **extremely** light, comprised with only a few files, which makes it very fast to run. | ||
<br /> | ||
**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: | ||
```js | ||
npm install ez.database | ||
``` | ||
--- | ||
# API Documentation | ||
With our step by step Guide, you can get started in seconds! | ||
<br /> | ||
**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: | ||
```js | ||
npm init -y | ||
``` | ||
**After that, please run the installation command for our Database.** | ||
--- | ||
### Setting up MongoDB | ||
#### Creating An Account | ||
To setup a **Database**, please visit **[MongoDB's Website](https://www.mongodb.com/)**. Next, click login, and from there, click sign up. You can either create and account, or sign up with **Google**. | ||
--- | ||
#### Installing MongoDB Compass | ||
Next, we're going to install **[MongoDB Compass](https://www.mongodb.com/try/download/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](https://www.mongodb.com/try/download/compass)**, 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**. 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 a file called MongoConnectionString.json, which will hold the string. Paste the following code into that file: | ||
```json | ||
{ | ||
"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: | ||
```js | ||
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, we're **requiring** the **MongoConnectionString** object, 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: | ||
```js | ||
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: | ||
<br /> | ||
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!** | ||
7901
0
159
Updatedmongodb@^3.6.2