@am92/mongo-odm

npm version  ECMAScript Module  License: MIT  Vulnerabilities: Snyk  Downloads Bundle Size


This is an ODM (Object Document Mapping) which provides CRUD functionalities to interact with MongoDB Collections. This package uses mongoose package using its 8.4.1 version.

This package provides the following functionalities:

  • MongoDB Connection Helper
  • Mongoose Schema Wrapper
  • Collection Modeling Class

Table of Content


Installation

Example :
npm install --save @am92/mongo-odm

Environment Variables

The following environment variables need to be set to work with this package:

Example :
##### Mongo Config
export MONGO_HOSTS=
export MONGO_DBNAME=
export MONGO_USER_AUTH=false
export MONGO_USERNAME=
export MONGO_PASSWORD=
export MONGO_REPLICASET=
export MONGO_REPLICASET_COUNT=0
export MONGO_READ_PREFERENCE=
export MONGO_SSL_ENABLED=false
export MONGO_SSL_VALIDATE=false
export MONGO_PEM_PATH=
export MONGO_MIN_POOL_SIZE=0
export MONGO_MAX_POOL_SIZE=100

Note: Do not export variable 'MONGO_READ_PREFERENCE' if no value is to be set.


Connecting to MongoDB

MongoDB needs to be connected before the 'Model' methods can executed. The connection can be established as shown below:

Example :
import { mongoConnect } from '@am92/mongo-odm'
await mongoConnect()

Contributors

Ankit Gandhi
Ankit Gandhi
Mehul Agarwal
Mehul Agarwal

Resources


License



results matching ""

    No results matching ""