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

@trigo/atrix-mongoose

v1.0.1

Published

mongoosse plugin as atrix data source

Downloads

20

Readme

Greenkeeper badge NSP Status

atrix-mongoose

mongoose plugin for atrix microservice framework

atrix manoggose plugin automaticaly sets up the connection to you mongo db using monggose models

Compatibility

atrix-mongoose < 1.0.0 works with atrix < 6.0.0 atrix-mongoose >= 1.0.0 works with atrix >= 6.0.0

Features

  • configuration driven
  • multi connection/database mgmt
  • GridFs (gridfs-stream) intigration

Installation

# install atrix framework
npm install -S @trigo/atrix

# install atrix-mongoose plugin
npm install -S @trigo/atrix-mongoose

# No need to install mongoose itself!

Usage & Configuration

models/TestModel.js


'use strict';

// ATTENTION: Do not require mongoose here!

module.exports = (mongoose) => {
	return new mongoose.Schema({
		name: {
			type: 'string'
		}
	});
}

models/factory.js


'use strict';

// ATTENTION: Do not require mongoose here!

module.exports = (mongoose, connection) => {
	return {
		TestModel: connection.model('TestModel', require('./TestModel')(mongoose)),
	};
}

handlers/GET.js

module.exports = (req, reply, service) => {
	// access model class for connection "m1"
	const TestModel_C1 = service.dataConnections.m1.schema.TestModel;
	
	// access GridFs (gridfs-stream) for connection "m1"
	const GridFs_C1 = service.dataConnections.m1.gridfs;
	
	// access the mongoose connection object for connection "m1"
	const Connection_C1 = service.dataConnections.m1.connection;
	
	// access the mongoose object (shared between all connections)
	const mongoose = service.dataConnections.m1.mongoose;
	
	// get model class for connection "m2" 
	const TestModel_C2 = service.dataConnections.m2.schema.TestModel;
	...
}

index.js

'use strict';

const atrix = require('@trigo/atrix');
const path = require('path');

const svc = atrix.addService({
	name: 'mongoose', 
	endpoints: {
		http: {
			// declare port to bind
      port: 3007,

      // the directory containing the handler files
      handlerDir: `${__dirname}/handlers`,
   	},
  },
	// declare a dataSource config section
	dataSource: {
		// name of the data source
		m1: {
			// type of data connection
			type: 'mongoose',
			// connection configuration
			config: {
				// path to the model factory module to be required by the plugin
				modelFactory: path.join(__dirname, './models/factory'),
				
				// database connection string
				connectionString: 'localhost:27017/test-atrix-mongoose-m1',
			},
		},
		m2: {
			type: 'mongoose',
			config: {
				modelFactory: path.join(__dirname, './models/factory'),
				connectionString: 'localhost:27017/test-atrix-mongoose-m2',
			},
		},
	},
});

// start service. 
// This will wait for the mongo connection to be available before starting up. 
// When conection(s) is lost after initial startup the plugin automatically tries to reconnect  
svc.start();

Run service with node index.js

Common issues

If you installed mongoose itself and your code requires it somewhere before the plugin is loaded, you have a good chance to break connection & model setup. Do not install mongoose itself!. If unsure simply run npm remove -S mongoose in your application root folder.

Contributing

If you update a package (especially mongoose) or the node version than you should run specs/failed-connection.specs.sh to ensure that the return codes on failed MongoDb connections are still correct.