2023.2.8 • Published 1 year ago

@ccondry/mongo-wrapper v2023.2.8

Weekly downloads
4
License
MIT
Repository
github
Last release
1 year ago

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))
2023.2.8

1 year ago

2022.10.18

2 years ago

2021.7.13

3 years ago

2021.7.8

3 years ago

2020.10.21

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago