mongoose-light
v1.0.6
Published
Simplify your MongoDB connections with Mongoose using just one line of code
Downloads
171
Maintainers
Readme
mongoose-light 🚀
Simplify your MongoDB connections with Mongoose using just one line of code, while maintaining full access to Mongoose functionality!
Installation
Install the package using npm:
npm install mongoose-light
Or using yarn:
yarn add mongoose-light
Usage
- Import the
initializeMongoDb
function andmongoose
from the package:
import { initializeMongoDb, mongoose } from 'mongoose-light';
- Call the
initializeMongoDb
function with your database configuration:
initializeMongoDb({
databaseUrl: process.env.DATABASEURL,
service: process.env.SERVICE,
});
- Use
mongoose
as you normally would for defining schemas, models, etc.
Configuration
The initializeMongoDb
function accepts an object with the following properties:
databaseUrl
(string): The URL of your MongoDB instance.service
(string): The name of your database service.
Example
import { initializeMongoDb, mongoose } from 'mongoose-light';
// Connect to MongoDB
initializeMongoDb({
databaseUrl: 'mongodb://localhost:27017',
service: 'myapp',
});
// Define a schema
const userSchema = new mongoose.Schema({
name: String,
email: String,
});
// Create a model
const User = mongoose.model('User', userSchema);
// Use the model
const newUser = new User({ name: 'John Doe', email: '[email protected]' });
newUser.save();
Features ✨
- Simple one-line connection to MongoDB
- Exports the
mongoose
object, allowing you to use all Mongoose features - Automatic connection error handling
- Console logging for successful connections
Dependencies
- mongoose: ^5.x.x
Why mongoose-light? 🤔
mongoose-light simplifies the process of connecting to MongoDB using Mongoose, while still providing full access to the Mongoose library. This allows you to:
- Quickly set up your database connection with minimal code
- Continue using Mongoose exactly as you're used to
- Keep your codebase clean and maintainable
License
MIT
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
Questions or Support
If you have any questions or need support, please open an issue on our GitHub repository.