@tonoid/mongo
v1.0.0
Published
MongoDB plugin for @tonoid/helpers
Downloads
4
Maintainers
Readme
@tonoid/mongo
MongoDB plugin for @tonoid/helpers. This plugin uses the NodeJS MongoDb client 6.
Init options
url
: (defaults:process.env.MONGO_URL
) MongoDB url, if set it overrides other auth options.host
: (defaults:process.env.MONGO_HOST || 'mongo'
) MongoDB host.port
: (defaults:process.env.MONGO_PORT || 27017
) MongoDB port.username
: (defaults:process.env.MONGO_USERNAME || 'mongo'
) MongoDB username.password
: (defaults:process.env.MONGO_PASSWORD || 'mongo'
) MongoDB password.authDb
: (defaults:process.env.MONGO_AUTH_DB || 'admin'
) MongoDB authentification database.dbName
: (defaults:process.env.MONGO_DB || 'test'
) MongoDB database.compressors
: (defaults:null
) Allow network compression: zlib, snappy, zstd (install correct dependency)
Exported context attributes
.close()
: Close mongo client.db(databaseName = options.dbName)
: Get database instance
Usage example
const { context, init } = require('@tonoid/helpers');
const mongo = require('@tonoid/mongo');
(async () => {
await init([
mongo({ url: 'mongodb://mongo:mongo@localhost:27017' }, 'myMongo'),
]);
const mongoDb = context.myMongo.db();
const products = await mongoDb.collection('products').find({});
console.log(products);
})();
Credits
This module is maintained by Simo Elalj @tonoid