mongodb.json

1.0.3 • Public • Published

mongodb.json - App success made simple

fast database with json extends mongoose style

Installing

$ npm init
$ npm install --save mongodb.json

fast database with json extends mongoose style

#setup

 const mongooseJson = require("mongodb.json") // mongooseJson it is the class of the package
 
 const usersSchema = { // normal javascript object and its the schema
    name: String, // String it is the type of the key
    age: Number, // Number it is the type of the key
    nickname: String, // String it is the type of the key
    password: String || Number 
}

const usersModel = new mongooseJson({
 path: "database.json" // its the file name
 dir: "database" // the dir of database.json file
}, usersSchema /* schema varible*/ ) 

how to create a new Data

async function createData() {
 const data = usersModel.findOneOrCreate({name: "hello"}) // -> {"name": "hello"}
}

how to find Data

async function findData() {
 const data = usersModel.findOne({name: "hello"}) 
 console.log(data) // -> {"name": "hello", id: "......"}
}

how to edit or add property

async function save() {
 const data = usersModel.findOne({name: "hello"}) 
 data.name = "ziad"
 data.password = 13313193201e
 data.nickname = "ziath"

 data.save()
}

how to delete data

async function delete() {
 const data = usersModel.findOne({name: "hello"}) 
 data.delete()
}

all current methods

methods Description
findOne find element
create create new Object
fetch get all data
findOneOrCreate find data or create new one

dev

Ziath#1768

Package Sidebar

Install

npm i mongodb.json

Weekly Downloads

0

Version

1.0.3

License

ISC

Unpacked Size

9.94 kB

Total Files

16

Last publish

Collaborators

  • polyer