@samwen/mongodb-utils
v1.0.7
Published
an useful collection of utils for mongodb operations
Downloads
15
Maintainers
Readme
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:[email protected]/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" } ]
})