Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@colucom/osseus-mongo

Package Overview
Dependencies
Maintainers
6
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@colucom/osseus-mongo

Osseus mongo

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15
Maintainers
6
Weekly downloads
 
Created
Source

JavaScript Style Guide

Osseus Mongo

mongoose based osseus mongodb connection module

Install

$ npm install @colucom/osseus-mongo

Usage

Configuration
  • OSSEUS_MONGO_URI - connection uri string
  • OSSEUS_MONGO_OPTIONS - connection options object, default is:
{
  "keepAlive": 1,
  "connectTimeoutMS": 30000,
  "socketTimeoutMS": 30000,
  "useMongoClient": true
}
Simple usage
  • Configuration file / secret: OSSEUS_MONGO_URI: 'mongodb://<mongosever>:<port>/<databasename>'
  • Model file (example: models/MyModel.js):
module.exports = (osseus) => {
    const db = osseus.mongo
    const mongoose = osseus.mongo.mongoose
    const Schema = mongoose.Schema

    const myModelSchema = new Schema({
        name: String
    });
    const MyModel = db.model('MyModel', myModelSchema)
    
    osseus.mongo.appModels = osseus.mongo.appModels || {}
    osseus.mongo.appModels['MyModel'] = MyModel
}
  • Require model after osseus init: require('./models/MyModel')(osseus);
  • You can access models by osseus.mongo.appModels['modelName'] from anywhere in the application. For example:
module.exports = (osseus) => {
    return {
        examplePOST: (req, res, next) => {
            const newMyModel = new osseus.mongo.appModels.MyModel({
                name: 'Someone'
            })

            newMyModel.save()
                .then(() => {
                    console.log('Document successfully saved')
                })
                .catch(err => {
                    throw err
                })
        }
    }
}

Contributing

Please see contributing guidelines.

License

Code released under the MIT License.

FAQs

Package last updated on 07 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc