1.0.0 • Published 4 years ago
database-manager-ff v1.0.0
Database Manager FF
This module allow access to mongodb collections which was previously on parse-server.
A couple of changes has been made to make this module compatible with existing record.
1. Modification of mongoose objectId prototype to not type cast
2. Plugins to auto generate reference (i.e foreign keys)
3. Auto generate models and schema from existing records
Usage
let DBM = require("database-manager-ff");
let databaseManager = await DBM({
onConnectionSucess: () => {
console.log("Connection successful");
},
onConnectionError: (e) => {
console.log('Error connecting', e)
},
generateSchemas: true,
generatorOptions: {
log: false, // to log?
overwriteModels: false // true will create new model files... all changes to models will be lost
},
cleanUp: true, // do close connection default=true
databaseUrl: process.env.DEFAULT_DATABASE_URI // database url
});
const { Meeting } = databaseManager.models
Availalble Options
Option | Required | Default | ?? |
---|---|---|---|
onConnectionSucess | false | console.log | function to run when connection is successful |
onConnectionError | false | console.log | functions to run when connection fails |
generateSchemas | false | false | whether to generate schema |
generatorOptions.log | true | false | whether to log or not |
generatorOptions.overwriteModels | false | false | to regenerate models (if true all existing models will be replaced |
cleanUp | false | true | to clean db connection after shutdown |
databaseUrl | true | process.env.MONGO_DATABASE_URL | database connection url |
Note
generateSchemas: true
requires that parse credentials are available. Required Credentials.
process.env.PARSE_SERVER_URL
process.env.PARSE_CLIENT_KEY
process.env.PARSE_MASTER_KEY
Performing Populate Queries
See: https://mongoosejs.com/docs/populate.html
Due to some changes to support existing data, you'll need to explicitly pass the getter true for populate to work
let record = await Meeting.findOne({ "_id": parseId })
.populate({
path: '_p_user',
options: {
getters: true
},
select: "fullName meetingSettings"
});
// records now contains user object as record._p_user
1.0.0
4 years ago