@samwen/mongodb-utils

1.0.7 • Public • Published

mongodb-utils

an useful collection of utils for mongodb operations

how to install

npm install @samwen/mongodb-utils --save

how to use

const { openDatabase, closeDatabase } = require('@samwen/mongodb-utils');
const mongodb_url = 'mongodb://username:password@database.domain.com/database?tls=true';

try {
    const database = await openDatabase(mongodb_url);
    await database.collection('test_collection').insertOne({started_at: Date.now(), key: 'test value'});
} catch(err) {
    console.error(err);
}
await closeDatabase();

note

in order to use mongodb_url in the specified format, you must create user under the database:

mongo shell commands:
use testdb
db.createUser({
    user: "testDbUser",
    pwd: "......",
    roles: [ { role: "readWrite", db: "testdb" } ]
})

Package Sidebar

Install

npm i @samwen/mongodb-utils

Weekly Downloads

0

Version

1.0.7

License

ISC

Unpacked Size

4.92 kB

Total Files

4

Last publish

Collaborators

  • samwen