0.1.0 • Published 4 years ago
@viewitjs/mongo-connector v0.1.0
ViewitJS Mongo Connector
Simple mongodb connector
Getting Started
Please install the package
npm i @viewitjs/mongo-connector
How to use it
Without database name
const MongoConnector = require('@viewitjs/mongo-connector')
const { client } = await MongoConnector({ url: 'mongodb://localhost:27017' })
const record = client
.dbName('my-db')
.collection('my-collection')
.find()
.toArray()
client.close()
With database name
const MongoConnector = require('@viewitjs/mongo-connector')
const { client, db } = await MongoConnector(
{ url: 'mongodb://localhost:27017' },
'my-db'
)
const record = db
.collection('my-collection')
.find()
.toArray()
With configuration
Parameters
- useEnv: Use the envioronment name to search in config
- default: false
- example: NODE_ENV = 'my-env'
- prefix: The mongo db prefix
- default: mongodb
- example: mongodb+srv
- user: The authentication user
- pass: The authentication password
- host: The mongo host
- port: The mongo port,
- authSource: The name of the database to authenticate if the connection string includes authentication
- dbOptions: A query string that specifies connection specific options as name=value&name=value
Without Env
const MongoConnector = require('@viewitjs/mongo-connector')
const { client, db } = await MongoConnector(
{
prefix: 'mongodb',
user: 'user',
pass: 'pass',
host: 'localhost'
port: '27017',
authSource: 'admin'
dbOptions: 'replicaSet=myRepl'
},
'my-db'
)
const record = db
.collection('my-collection')
.find()
.toArray()
With Env
NODE_ENV = 'my-env'
const MongoConnector = require('@viewitjs/mongo-connector')
const { client, db } = await MongoConnector(
useEnv: true
'my-env': {
prefix: 'mongodb',
user: 'user',
pass: 'pass',
host: 'localhost'
port: '27017',
authSource: 'admin'
dbOptions: 'replicaSet=myRepl'
},
'my-db'
)
const record = db
.collection('my-collection')
.find()
.toArray()
Prerequisites
Before installing, download and install Node.js
V8 or higher is required.
Development
If you want to parcipate please visit mongo-connector
Navigate to a project folder where you want to work and fork the repository
git fork git@github.com:viewitjs/mongo-connector.git {package name}
Install all dev dependencies
npm install
Create new branch and start work & enjoy it
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We are in firsts stages of the development. If you want to contribute with this project please visit:
Authors
- Diego Londoño - Viewit Team
- Elias Valdez - Viewit Team
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Acknowledgments
- To all interested contributors
0.1.0
4 years ago