3.3.23 • Published 2 years ago

kth-node-mongo v3.3.23

Weekly downloads
13
License
MIT
Repository
github
Last release
2 years ago

kth-node-mongo Build Status

Database connection wrapping Mongoose (for MongoDB)

This module connects to mongoDB using Mongoose default connection.

To use this module

Connect to database

  1. Import module
    const nodeMongo =require('kth-node-mongo')

  2. Connect to mongoDB over SSL: nodeMongo.connect(options, sslOptions) or

  3. Connect to mongoDB without SSL: nodeMongo.connect(options)

  4. Use Mongoose schema and model to interact with mongoDB

Function connect() returns a promise to be resolved upon completed connection or rejected on error.

Options

  • dbUsername (required) Credentials, the database user

  • dbPassword (required) Credentials, the password for the database user

  • dbUri (required) The URI for the mongoDb to connect to

  • logger (optional) A logger to use, defaults to stdout(console.log)

SSL(TLS) Options

  • ssl (optional) Boolean flag if database connection shoold be encrypted or not

  • authDatabase (optional) If login credentials are used, specifies which database to use for authentication of user. Can also be sent as part of dbUri.

  • caCerts (optional) A list of buffers or strings containing the ca certificates (.pem) we accept when setting up the secure connetion.

Example without secure database connction

nodeMongo
  .connect({
    dbUsername: 'user',
    dbPassword: 'himligt',
    dbUri: 'mongodb://localhost/le_database?authSource=authDB',
    logger: log,
  })
  .then(() => log.debug('Connected to Mongo'))
  .catch(err => log.error(err))

Example with secure database connction

nodeMongo
  .connect(
    {
      dbUsername: 'user',
      dbPassword: 'himligt',
      dbUri: 'mongodb://localhost/le_database',
      logger: log,
    },
    {
      ssl: true,
      authenticationDatabase: 'authDB',
      sslCA: certs,
    }
  )
  .then(() => log.debug('Connected to Mongo'))
  .catch(err => log.error(err))

Check status of connection

  1. Import module
    const nodeMongo =require('kth-node-mongo')

  2. Check connection:

    if (nodeMongo.isOk()) {
      // OK
    } else {
      // ERROR
    }
3.3.23

2 years ago

3.3.22

3 years ago

3.3.21

3 years ago

3.3.20

3 years ago

3.3.19

3 years ago

3.3.18

3 years ago

3.3.16

3 years ago

3.3.17

3 years ago

3.3.15

3 years ago

3.3.14

3 years ago

3.3.13

3 years ago

3.3.11

3 years ago

3.3.12

3 years ago

3.3.10

3 years ago

3.3.9

3 years ago

3.3.8

3 years ago

3.3.7

4 years ago

3.3.6

4 years ago

3.3.5

4 years ago

3.3.4

4 years ago

3.3.3

4 years ago

3.3.2

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.4

4 years ago

3.2.3

4 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

7 years ago

1.0.7

7 years ago