1.1.0 โ€ข Published 3 years ago

mongoi v1.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

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 ๐Ÿ˜