npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

feathers-mongodb-management

v2.0.1

Published

Feathers service adapters for managing MongoDB databases, collections and users

Downloads

439

Readme

feathers-mongodb-management

Build Status Code Climate Test Coverage Download Status

Feathers service adapters for managing MongoDB databases, users and collections

Installation

With NPM npm install feathers-mongodb-management --save or Yarn yarn add feathers-mongodb-management

v1.x is expected to work with Feathers v3 (a.k.a Buzzard) and NodeJS v12

v2.x is expected to work with Feathers v5 (a.k.a Dove) and NodeJS v16

Documentation

If a large number of users require it a more complete feathers-mongodb-management documentation will be created. For now as the API is pretty straigth forward the example and tests should be sufficient to understand how it works.

The initial use case was to simplify data segregation for a SaaS application where each user could belong to different organisations like in GitHub. Indeed, one key aspect of access control is to filter the resources a user can reach. In this specific use case the users always work in the context of an organisation acting as a filter applied on the manipulated resources. This issue is often tackled by applying a client-side filter on a global service like /users?org=orgId and storing on each resouce the organisation it belongs to. We consider this approach as more harder to maintain in the long-term due to additional filtering and relations in the data model. As a consequence we created this plugin to "physically" separate the data of each organisation in a dedicated DB instead of doing this "logically" using filtering.

You can find more information by reading this article.

Complete Example

Here's an example of a Feathers server that uses feathers-mongodb-management.

const feathers = require('feathers');
const rest = require('feathers-rest');
const hooks = require('feathers-hooks');
const bodyParser = require('body-parser');
const errorHandler = require('feathers-errors/handler');
const mongodb = require('mongodb');
const plugin = require('feathers-mongodb-management');

// Initialize the application
const app = feathers()
  .configure(rest())
  .configure(hooks())
  // Needed for parsing bodies (login)
  .use(bodyParser.json())
  .use(bodyParser.urlencoded({ extended: true }))
  .use(errorHandler());

// Connect to Mongo instance
const client = await mongodb.MongoClient.connect('mongodb://127.0.0.1:27017')
// Initialize your feathers plugin to manage databases
app.use('/mongo/databases', plugin.database({ adminDb: client.db('feathers-test').admin(), client }));
let dbService = app.service('/mongo/databases');
// Now create a new database
let db = await dbService.create({ name: 'test-db' })
// The objects provided through the plugin services are just metadata and not MongoDB driver instances
// We need to retrieve it to create collection/user services that require the DB instance
db = client.db('test-db');
// Now create services binded to this database to manage collections/users
app.use('/mongo/test-db/collections', plugin.collection({ db }));
let collectionService = app.service('/mongo/test-db/collections');
const collection = await collectionService.create({ name: 'test-collection' })
app.use('/mongo/test-db/users', plugin.user({ db }));
let userService = app.service('/mongo/test-db/users');
const user = await userService.create({ name: 'test-user', password: 'test-password', roles: ['readWrite'] })
// Perform other operations using these services if required
...
// Then start the app
app.listen(3030);
console.log('Feathers app started on 127.0.0.1:3030');

License

Copyright (c) 2016

Licensed under the MIT license.