UNPKG

mongo-client-db

Version:

Simple Connect, Backup, and Restore Database JSON With Mongo DB

60 lines (51 loc) 1.59 kB
## Simple Mongo DB Client Connect<br> Example<br> ```ts /** from module CommonJS **/ const { backup, restore } = require('mongo-client-db'); /** from module ESM Module **/ const { backup, restore } = await import('mongo-client-db'); /** name file path your database JSON! **/ const file_restore = './database.json' /** * password database monggo * how to find? go to your project * at Security click Database Access * if you don't have one create it * follow the instructions * and you gonna find password * generate it and copy **/ const password = 'hkv8dLObQ8l3shnmt' /** * your url database example * how to find ? * at Deployment click connect * then click Driver * and you gonna see the url * replace password with ${password} **/ const url = `mongodb+srv://myname:${password}@cluster0.shgob.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0` /** example data (parsing or global.db) * your database path must be object {} if array [] i haven't try it **/ const data = JSON.parse(fs.readFileSync('./database.json')) // to backup async function Backup(data) { const response = await backup(url, data); console.log(response) return response // to do get result from other file } Backup(data) // use // to restore async function Restore() { const response = await restore(url, file_restore); console.log(response.log) //showing log // or console.log(response.data) //showing data return response // to do get result from other file } // the important thing setup your ip address at Security => Network Access Restore() ```