Socket
Socket
Sign inDemoInstall

odmongo

Package Overview
Dependencies
17
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    odmongo

Barebones MongoDB ODM.


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

1.0.0-beta.1 / 2020-08-08

  • Adds native ES module exports.
  • Adds more aggregation builder methods. In particular, facet() and lookup().
  • Require Node.js 10+.

Readme

Source

odmongo

A barebones MongoDB ODM designed for use with modern ES syntax.

It provides a very small wrapper that you can extend in various places to build yourself a nice DB library.

Usage

In short:

const joi = require('joi')
const { Connection, Model } = require('odmongo')

// Set up a connection instance
const connection = new Connection()

// Create some Model classes
class User extends Model {
  validate () {
    return joi.validate(this.fields, User.schema)
  }
}
User.schema = joi.object({
  username: joi.string().required()
})
User.collection = 'users'

// Register models on the connection instance
connection.define({ User })

// Connect!
await connection.connect('mongodb://localhost:27017/my_db')

// Query existing documents
for await (const user of connection.models.User.find()) {
  console.log(user.fields.username)
}

// Create new documents
const user = new connection.models.User({
  username: 'Me'
})
try {
  await user.save()
  console.log('saved')
} catch (err) {
  console.error('Could not save the new user:', err.message)
}

API

See the documentation in API.md.

License

Apache-2.0

Keywords

FAQs

Last updated on 08 Aug 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc