1.1.0 โข Published 3 years ago
mongoi v1.1.0
MONGOI๐
MONGOI is a npm package made by Fadhil
easy tool to manage and do CRUD operation with mongo database
Setup
npm i mongoi
How To Use
Mongoi will help you to do crud operation ๐ฑ
to have more features don't forget to contribute ๐
After installing require it
const mongoi = require('mongoi')
you have initialize it first
let yourDatabaseConnectionUrl = "mongodb://localhost:27017/[you-db-name]"
// create database schema as you do for mongoose
let databaseSchema = {
name: String,
}
let collectionName = "your-collection-name"
mongoi.init(yourDatabaseConnectionUrl, databaseSchema, collectionName).then(()=>{
// you can write anything here except bug ๐
})
now you initialized mongoi successfully ๐
so lets start doing crud ๐
CRUD = CREATE - READ - UPDATE - DELETE
// This is the model of crud ๐ช
mongoi.crud([option], data).then(()=>{
// use it ๐
})
// options
// [you have to write it in string eg : "r"]
//
// s - "save"
// r = "read"
// ro = "read one"
// u = "update many"
// uo = "update one"
// d = "delete all"
// do = "delete one"
// dm = "delete many"
//
// Enjoy ๐ค
//
Create
lets create ๐ป
// create this according to you schema
const data_to_save = {
name: "apple",
color: "red"
}
mongoi.crud("s", data_to_save) // you can call .then after this ๐ฅฑ
Read
lets read ๐
// read all
mongoi.crud("r").then((data_you_get_from_database)=>{
// do with this data ๐ผ
})
// read one
let condition = {name: "panda"} // this is the condition of what are you looking for
mongoi.crud("ro", condition).then((data_you_get_from_database)=>{
// do with this data ๐ง
})
Update
let update ๐
// update many or update all
let condition_and_data = [
{cute_message: "you are ugly ๐คฎ"},//this should be condition
{cute_message: "you are cute ๐"}//thing you wan't to change
]
mongoi.crud("u", condition_and_data)// you can call .then after this ๐ฅฑ i don't care ๐
// ๐
/*
let condition_and_data = [
{cute_message: "you are cute ๐"},//you are not cute ๐
{cute_message: "you are ugly ๐คฎ"}//you are ugly ๐
]
mongoi.crud("u", condition_and_data)// just kidding ๐
*/
// update one
let condition_and_data = [
{cute_message: "you are ugly ๐คฎ"},//this should be condition
{cute_message: "you are cute ๐"}//thing you wan't to change
]
mongoi.crud("uo", condition_and_data)// you can call .then after this ๐ฅฑ i don't care ๐
// ๐
/*
let condition_and_data = [
{cute_message: "you are cute ๐"},//you are not cute ๐
{cute_message: "you are ugly ๐คฎ"}//you are ugly ๐
]
mongoi.crud("u", condition_and_data)// just kidding ๐
Delete
lets delete this ๐งบ
// delete all
mongoi.crud("d") // .then is supported ๐
// delete many
let condition = {cute_message: "you are cute"}
mongoi.crud("dm", condition)// use .then if you want
// delete one
let condition = {cute_message: "you are cute"}
mongoi.crud("do", condition)// use .then if you want no one cares ๐
Conclusion
Hopefully I assume that you love ๐ this
contribute for updating this garbage ๐