@ccondry/mongo-wrapper
A simple wrapper for mongodb. Handles connection pooling for you.
Last updated 2 months ago by ccondry .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @ccondry/mongo-wrapper 
SYNC missed versions from official npm registry.

mongo-wrapper

A simple wrapper for mongodb. Handles connection pooling for you.

Example

// this library
const mongo = require('@ccondry/mongo-wrapper')

// your mongo database URL / connection string
const url = 'mongodb+srv://user:password@host/?retryWrites=true'
// optional - these are the default values
const connectOptions = {
  useNewUrlParser: true,
  poolSize: 5, 
  useUnifiedTopology: true
}
// optional - this is the default value
const logLevel = 1

// create the wrapper object
const db = new mongo(url, connectOptions, logLevel)

// this would also work to create the wrapper object
// const db = new mongo(url)

// set up projection to exclude password from results
const projection = {password: 0}

// find one user in the toolbox database, excluding the password field
db.findOne('toolbox', 'users', {email: 'ccondry@cisco.com'}, {projection})
.then(r => console.log('found user:', r))
.catch(e => console.log('error:', e.message))

// find list of enabled users in the toolbox database, excluding the password field
db.find('toolbox', 'users', {disabled: false}, projection)
.then(r => console.log('found user:', r))
.catch(e => console.log('error:', e.message))

Current Tags

  • 2021.7.13                                ...           latest (2 months ago)

9 Versions

  • 2021.7.13                                ...           2 months ago
  • 2021.7.8                                ...           3 months ago
  • 2020.10.21                                ...           a year ago
  • 1.5.0                                ...           a year ago
  • 1.4.0                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.1                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 9
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2021 © npmmirror.com |