1.2.0 • Published 2 years ago

@samwen/mongodb v1.2.0

Weekly downloads
215
License
ISC
Repository
github
Last release
2 years ago

mongodb

A Mongodb class for basic open close getClient operations

how to install

npm install @samwen/mongodb

how to use

const Mongodb = require('@samwen/mongodb');

const mongodb_url = 'mongodb://username:password@database.domain.com/testdb?tls=true';

const mongodb = new Mongodb(mongodb_url);
try {
    const database = await mongodb.open();
    await database.collection('test_collection').insertOne({started_at: Date.now(), key: 'test value'});
} catch(err) {
    console.error(err);
} finally {
    await mongodb.close();
}

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" } ]
})

OR

const Mongodb = require('@samwen/mongodb');

const mongodb_url = 'mongodb://username:password@database.domain.com/?authSource=admin&tls=true';

const mongodb = new Mongodb(mongodb_url);
try {
    const collection = await mongodb.open('testdb', 'test_collection');
    await collection.insertOne({started_at: Date.now(), key: 'test value'});
} catch(err) {
    console.error(err);
} finally {
    await mongodb.close();
}

note

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

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

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago