@am92/mongo-odm
v2.0.7
Published
Mongo DB ODM (Object Document Mapper)
Downloads
132
Readme
@am92/mongo-odm
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
npm install --save @am92/mongo-odm
Environment Variables
The following environment variables need to be set to work with this package:
##### 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:
import { mongoConnect } from '@am92/mongo-odm'
await mongoConnect()