0.0.4 • Published 6 months ago

mongo-client-db v0.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

Simple Mongo DB Client Connect

Example

/** 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() 
0.0.3

6 months ago

0.0.4

6 months ago

0.0.2

9 months ago

0.0.1

9 months ago