
Security Fundamentals
Turtles, Clams, and Cyber Threat Actors: Shell Usage
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.
easy-mongo-orm
Advanced tools
A powerful and elegant MongoDB/Mongoose toolkit that makes database operations a breeze with built-in caching, search, pagination, performance monitoring, soft delete, versioning, data export/import, schema validation, and migration utilities
A powerful and elegant MongoDB/Mongoose toolkit that makes database operations a breeze with built-in caching, search, pagination, performance monitoring, soft delete, versioning, data export/import, schema validation, and migration utilities.
npm install easy-mongo-orm mongoose
const { EasyMongo } = require('easy-mongo-orm');
// Initialize with your model configuration
const userDb = new EasyMongo({
connection: {
uri: 'mongodb://localhost:27017/mydb'
},
model: {
name: 'User',
schema: {
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
age: Number,
tags: [String]
},
options: {
timestamps: true
}
},
features: {
enableCache: true,
enablePerformanceMonitoring: true
}
});
// Connect to database
await userDb.connect();
// CRUD Operations
const user = await userDb.create({
name: 'John Doe',
email: 'john@example.com',
age: 30,
tags: ['developer']
});
// Search Operations
const results = await userDb.search({
text: 'John',
fields: ['name']
});
// Pagination
const { data, pagination } = await userDb.paginate(
{ age: { $gt: 25 } },
{ page: 1, limit: 10 }
);
// Performance Stats
const stats = userDb.getPerformanceStats();
const results = await userDb.search({
text: 'developer',
fields: ['tags', 'bio']
});
const nearbyUsers = await userDb.searchNearby({
coordinates: [-73.935242, 40.730610],
maxDistance: 1000 // meters
});
const results = await userDb.fuzzySearch({
field: 'name',
query: 'jhon' // will match "John"
});
const users = await userDb
.query()
.where({ age: { $gt: 25 } })
.select('name email')
.sort('-createdAt')
.limit(10)
.execute();
const stream = userDb
.largeDataset()
.where({ status: 'active' })
.stream();
for await (const doc of stream) {
// Process each document
}
await userDb.withTransaction(async (session) => {
const user = await userDb.create({
name: 'Alice',
email: 'alice@example.com'
}, { session });
await userDb.create({
name: 'Bob',
email: 'bob@example.com'
}, { session });
});
// First call hits database
const user1 = await userDb.findOne({ email: 'john@example.com' });
// Second call uses cache
const user2 = await userDb.findOne({ email: 'john@example.com' });
// Clear specific cache
await userDb.clearCache('email:john@example.com');
// Clear all cache
await userDb.clearAllCache();
const stats = userDb.getPerformanceStats();
console.log(stats);
// {
// operations: {
// create: { count: 10, totalTime: 150, averageTime: 15 },
// find: { count: 20, totalTime: 180, averageTime: 9 }
// },
// totalQueries: 30,
// averageQueryTime: 11,
// errors: 0
// }
// Enable soft delete in features
const userDb = new EasyMongo({
// ... other config
features: {
enableSoftDelete: true,
softDelete: {
deletedField: 'isDeleted', // default
deletedAtField: 'deletedAt' // default
}
}
});
// Soft delete a document
await userDb.softDeleteById('60d21b4667d0d8992e610c85');
// Soft delete multiple documents
await userDb.softDelete({ status: 'inactive' });
// Restore a soft-deleted document
await userDb.restoreById('60d21b4667d0d8992e610c85');
// Restore multiple soft-deleted documents
await userDb.restore({ status: 'inactive' });
// Find including soft-deleted documents
const allUsers = await userDb.findWithDeleted({});
// Find only soft-deleted documents
const deletedUsers = await userDb.findOnlyDeleted({});
// Enable versioning in features
const userDb = new EasyMongo({
// ... other config
features: {
enableVersioning: true,
versioning: {
historyCollectionName: 'UserHistory' // default is modelName + 'History'
}
}
});
// Create, update, and delete operations automatically track changes
// Get document history
const history = await userDb.getDocumentHistory('60d21b4667d0d8992e610c85');
// Returns array of versions with changes
// Get specific version
const v2 = await userDb.getDocumentVersion('60d21b4667d0d8992e610c85', 2);
// Revert to a previous version
await userDb.revertToVersion('60d21b4667d0d8992e610c85', 2, {
user: 'admin@example.com' // optional user info for audit trail
});
// Enable data export in features
const userDb = new EasyMongo({
// ... other config
features: {
enableDataExport: true
}
});
// Export to JSON
await userDb.exportToJson(
{ status: 'active' }, // filter
'./exports/active-users.json', // file path
{
projection: { password: 0 }, // exclude fields
sort: { createdAt: -1 }
}
);
// Export to CSV
await userDb.exportToCsv(
{ status: 'active' },
'./exports/active-users.csv',
{
fields: ['name', 'email', 'createdAt'] // specify fields to export
}
);
// Export large dataset with streaming
await userDb.exportLargeDatasetToJson(
{ status: 'active' },
'./exports/all-active-users.json',
{ batchSize: 1000 }
);
// Import from JSON
await userDb.importFromJson(
'./imports/users.json',
{
replace: false, // don't clear collection before import
upsert: true, // update existing documents
idField: '_id' // field to use for matching existing documents
}
);
// Import from CSV
await userDb.importFromCsv(
'./imports/users.csv',
{
fieldTypes: {
age: 'number',
isActive: 'boolean',
joinDate: 'date'
}
}
);
// Enable schema validation in features
const userDb = new EasyMongo({
// ... other config
features: {
enableSchemaValidator: true
}
});
// Get common validation schemas
const Joi = require('joi');
const commonSchemas = SchemaValidator.createCommonSchemas();
// Define a validation schema
userDb.defineValidationSchema(Joi.object({
name: Joi.string().required(),
email: commonSchemas.email.required(),
password: commonSchemas.password,
age: Joi.number().min(18).max(100),
role: Joi.string().valid('user', 'admin', 'editor')
}));
// Validate data
try {
const validatedData = userDb.validate({
name: 'John Doe',
email: 'invalid-email',
age: 15
});
} catch (error) {
console.log(error.details);
// [
// { field: 'email', message: 'must be a valid email', type: 'string.email' },
// { field: 'age', message: 'must be at least 18', type: 'number.min' }
// ]
}
// Async validation
const validatedData = await userDb.validateAsync(data);
// Enable migration in features
const userDb = new EasyMongo({
// ... other config
features: {
enableMigration: true
}
});
// Register a migration
userDb.registerMigration({
name: 'add-status-field',
version: 1,
description: 'Add status field to all users',
up: async () => {
// Create a migration helper
const helper = userDb.migrationManager.createMigrationHelper(userDb.Model);
// Add a field to all documents
await helper.addField('status', 'active');
},
down: async () => {
const helper = userDb.migrationManager.createMigrationHelper(userDb.Model);
await helper.removeField('status');
}
});
// Register another migration
userDb.registerMigration({
name: 'rename-bio-to-description',
version: 2,
description: 'Rename bio field to description',
up: async () => {
const helper = userDb.migrationManager.createMigrationHelper(userDb.Model);
await helper.renameField('bio', 'description');
},
down: async () => {
const helper = userDb.migrationManager.createMigrationHelper(userDb.Model);
await helper.renameField('description', 'bio');
}
});
// Apply all pending migrations
const result = await userDb.applyMigrations();
console.log(`Applied ${result.applied} migrations`);
// Get migration status
const status = await userDb.getMigrationStatus();
console.log(`Applied migrations: ${status.applied.length}`);
console.log(`Pending migrations: ${status.pending.length}`);
// Rollback the last migration
await userDb.rollbackLastMigration();
{
uri: 'mongodb://localhost:27017/mydb',
options: {
useNewUrlParser: true,
useUnifiedTopology: true
// ... other mongoose connection options
}
}
{
// Core features
enableCache: true,
cacheTTL: 3600, // seconds
enablePerformanceMonitoring: true,
enableRateLimit: true,
rateLimit: {
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // requests per windowMs
},
// New features
enableSoftDelete: true,
softDelete: {
deletedField: 'isDeleted',
deletedAtField: 'deletedAt'
},
enableVersioning: true,
versioning: {
historyCollectionName: 'CustomHistoryCollection'
},
enableDataExport: true,
dataExport: {
// export options
},
enableSchemaValidator: true,
schemaValidator: {
// validation options
},
enableMigration: true,
migration: {
// migration options
}
}
Contributions are welcome! Please feel free to submit a Pull Request.
MIT © Md.Tousif
FAQs
A powerful and elegant MongoDB/Mongoose toolkit that makes database operations a breeze with built-in caching, search, pagination, performance monitoring, soft delete, versioning, data export/import, schema validation, and migration utilities
We found that easy-mongo-orm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
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.
Security Fundamentals
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.
Security News
At VulnCon 2025, NIST scrapped its NVD consortium plans, admitted it can't keep up with CVEs, and outlined automation efforts amid a mounting backlog.
Product
We redesigned our GitHub PR comments to deliver clear, actionable security insights without adding noise to your workflow.