0.0.4 • Published 9 months ago

astro-mongoose v0.0.4

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

Astro Plugin Mongoose

astro-mongoose is a plugin for integrating Mongoose with your Astro project, enabling seamless MongoDB connections and enhanced Developer Experience (DX) features.

Table of Contents

Features

  • Easy MongoDB Connection: Quickly connect to MongoDB using Mongoose in astro project.
  • Configurable Options: Customize connection parameters with ease.
  • Automatic Connection Management: Handles reconnections and disconnections automatically.
  • Detailed Logging: Get clear and descriptive logs for connection states.
  • Graceful Shutdown: Cleans up connections properly on server shutdown or interruption.
  • Error Handling: Provides meaningful error messages for connection issues.

Installation

You can install the plugin via npm:

npm install astro-mongoose mongoose

Usage

Basic Example

To get started, add astro-mongoose in astro config file

import mongoose from "astro-mongoose";

export default {
  integrations: [
    mongoose(process.env.MONGODB_URI, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    }),
  ],
};

Advanced Configuration

You can customize the connection with additional options:

import mongoose from "astro-mongoose";
import type { ConnectOptions } from "mongoose";

const mongooseOptions: ConnectOptions = {
  useNewUrlParser: true,
  useUnifiedTopology: true,
};

export default {
  integrations: [mongoose(process.env.MONGODB_URI, mongooseOptions)],
};

Options

OptionTypeDescription
uristringThe MongoDB connection string (required).
optionsConnectOptionsAdditional Mongoose connection options (optional).

Connection Lifecycle

The plugin automatically manages the MongoDB connection lifecycle:

  • Connects when the Astro server starts.
  • Closes the connection gracefully on server stop or interruption.
  • Logs connection status and any errors.

Error Handling

The plugin throws an error if the MongoDB URI is not provided during initialization. Custom error messages are logged during connection attempts and when closing the connection.

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago