Giter Club home page Giter Club logo

mongocruise's Introduction

workflow codecov

Mongocruise

"A smooth, trouble-free journey through your MongoDB collections with simple RESTful APIs."

Mongocruise is a flexible, user-friendly plugin for the Hapi.js server framework. It provides an intuitive way to create MongoDB-backed HTTP routes.

Features

  • Easily define CRUD operations in your Hapi.js routes.
  • Flexible route parameters that leverage MongoDB's search capabilities.
  • Supports various MongoDB operations including find, findOne, insertOne, updateOne, and deleteOne.

Installation

npm install mongocruise

Prerequisites

This plugin requires a MongoDB connection registered on the server using the mongokai Hapi.js plugin. The connection is exposed via a property server.mongo.db.

Usage

  1. Register the plugin:
await server.register(require('mongocruise'))
  1. Use the mongocruise handler in your route configurations:
{
  method: 'GET',
  path: '/users',
  handler: {
    mongocruise: {
      collection: 'users',
      operation: 'find',
    }
  }
}

The mongocruise handler supports the following options:

  • collection: The MongoDB collection to use.
  • operation: The MongoDB operation to perform. Can be one of find, findOne, insertOne, updateOne, or deleteOne.
  • queryParam: The parameter to use for findOne, updateOne, and deleteOne operations.
  • setTimestamps: The flag to add createdAt or updatedAt on the create and update operations.

For find operations, query parameters such as skip, limit, sort, projection, and find can be passed directly in the request. These parameters should be in JSON format.

Example

{
  method: 'GET',
  path: '/users/{id}',
  handler: {
    mongocruise: {
        collection: 'users',
        operation: 'findOne',
        queryParam: '_id'
    }
  }
}

This route configuration would use the findOne operation on the users collection, using the _id route parameter to find a specific user.

Error Handling

If an invalid operation is passed in, or if there's an issue with the request's query parameters, mongocruise will throw an error.

Testing

This plugin is thoroughly unit tested. Please refer to the tests in the /test directory for more examples of how to use the plugin.

Contribution

Contributions are welcome! Please submit a pull request and ensure your changes pass the existing tests and linting rules.

License

This project is licensed under the MIT License. See the license file for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.