2.0.9 • Published 9 months ago
@pecoding/mongoose-schema v2.0.9
Mongoose Schema Central Repository
This project provides a centralized collection of Mongoose schemas used across various Node.js projects within XXX. It ensures consistency and reusability of schema definitions, minimizing duplication and simplifying maintenance across the company’s projects.
Purpose
In many Node.js projects within the company, the same data models are reused. To ensure consistency and maintainability, this package centralizes schema definitions, making it easier to update and manage models across all relevant projects.
Installation
Install the package via npm:
npm install @pecoding/mongoose-schema
Usage
This package exports multiple Mongoose models, schemas, and validation functions. Below is a summary of the available exports and their intended usage.
Exported Models and Schemas
Agents
agents
: Mongoose model for theagents
collection.agent_schema
: Schema definition foragents
.validationAgent
: Function to validateagents
data.validateSearchAgent
: Function to validate search parameters for agents.validationUpAgent
: Validation function for updatingagents
data.
Config Agents
config_agents
: Mongoose model for theconfig_agents
collection.config_agents_schema
: Schema definition forconfig_agents
.
OAuth
oauths
: Mongoose model for theoauths
collection.oauth_schema
: Schema definition foroauths
.
Games Lists
games_lists
: Mongoose model for thegame_lists
collection.game_custom_lists
: Mongoose model for thegame_custom_lists
collection.game_list_schema
: Schema definition forgame_lists
.game_custom_schema
: Schema definition forgame_custom_lists
.
Lunchings
lunchings
: Mongoose model for thelunchings
collection.lunching_schema
: Schema definition forlunchings
.
Announcements
announcements
: Mongoose model for theannouncements
collection.announcement_schema
: Schema definition forannouncements
.
Maintenances
maintenances
: Mongoose model for themaintenances
collection.maintenance_schema
: Schema definition formaintenances
.
Members
members
: Mongoose model for themembers
collection.member_schema
: Schema definition formembers
.validationMember
: Function to validatemember
data.validateSearchUser
: Function to validate search parameters for members.validationupMember
: Validation function for updatingmember
data.validationpass
: Validation function for member passwords.
Daily Reports
dailyReportSimples
: Mongoose model for thedailyReportSimples
collection.dailyReportsProducts
: Mongoose model fordailyReportSimples
.dailyReports
: Mongoose Mongoose model for thedailyReports
collection.dailyReportSimples_schema
: Schema definition fordailyReportSimples
.dailyReportsProducts_schema
: Schema definition fordailyReportSimples
.dailyReports
: Schema definition fordailyReports
.
Reports
reports
: Mongoose model for thereports
collection.report_schema
: Schema definition forreports
.
Importing the schema
const mongoose = require('mongoose');
const { members, validationMember, agents } = require('@pecoding/mongoose-schema');
// Connect to MongoDB
mongoose.connect('mongodb://localhost:27017/mydatabase', {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log('MongoDB connected!'))
.catch((err) => console.error('Connection error:', err));
// Example usage of the members model
const newMember = new members({
name: 'Jane Doe',
email: 'jane.doe@example.com',
age: 28
});
// Validate the member data before saving
if (validationMember(newMember)) {
newMember.save()
.then(member => console.log('Member saved:', member))
.catch(err => console.error('Error saving member:', err));
} else {
console.error('Member validation failed');
}