1.2.0 • Published 3 years ago
@samwen/mongodb v1.2.0
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
3 years ago
1.1.9
3 years ago
1.1.8
3 years ago
1.1.7
3 years ago
1.1.6
3 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago