ezpz.db
v2.1.0
Published
ezpz database for mongodb
Downloads
28
Maintainers
Readme
ezpz.db
A package to make using mongodb easier and user friendly!
Install ✨
npm install ezpz.db
Usage 💻
const db = require('ezpz.db');
db.connect('mongodb://localhost/my_database', {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
}) //same as mongoose's connect function
Main methods
/*--------------------Adding a data to an id--------------------*/
db.set("player", {wallet: 500})
// "player" is the id
// {wallet: 500} is the data
db.get("player").then(p => {
// `wallet` will be false if `db.get()` cant find the document
if (!p) return console.log(0) // -> 0
console.log(p.wallet) // -> 500
})
/*--------------------------------------------------------------*/
/*---------------------Deleting a data---------------------*/
db.delete("player")
db.get("player").then(p => console.log(p)) // -> false
/*---------------------------------------------------------*/
Dynamic methods
/*--------------------------------Get all data from collection--------------------------------*/
// Lets add a new object first
db.set("player2", {wallet: 100, items: ["bow","arrows"]})
// the `all()` function is a promise that returns an array
db.all().then(all => console.log(all))
/*
[
{id: "player", {data: {wallet: 500}}},
{id: "player2", {data: {wallet: 100, items: ["bow", "arrows"]}}},
]
*/
/*--------------------------------------------------------------------------------------------*/
/*----Delete everythng in the collection----*/
db.empty()
db.all().then(all => console.log(all))
// -> []
/*------------------------------------------*/
Have an issue? 🚨
Let me know in my discord server