feathers-mongoose
Create a Mongoose ORM wrapped service for FeathersJS.
Installation
npm install feathers-mongoose --save
Documentation
Please refer to the Feathers database adapter documentation for more details or directly at:
- Mongoose - The detailed documentation for this adapter
- Extending - How to extend a database adapter
- Pagination - How to use pagination
- Querying and Sorting - The common adapter querying mechanism and sorting for the database adapter
Getting Started
Creating an Mongoose service is this simple (make sure your MongoDB server is up and running):
var mongoose = ;var MongooseModel = var mongooseService = ; mongoosePromise = globalPromise;mongoose; app;
See the Mongoose Guide for more information on defining your model.
Complete Example
Here's a complete example of a Feathers server with a message
mongoose-service.
const feathers = ;const rest = ;const socketio = ;const errors = ;const bodyParser = ;const mongoose = ;const service = ; // Require your modelsconst Message = ; // Tell mongoose to use native promises// See http://mongoosejs.com/docs/promises.htmlmongoosePromise = globalPromise; // Connect to your MongoDB instance(s)mongoose; // Create a feathers instance.const app = // Enable Socket.io // Enable REST services // Turn on JSON parser for REST services // Turn on URL-encoded parser for REST services ; // Connect to the db, create and register a Feathers service.app; // Connect to the db, create and register a Feathers service with analogId, if analogId set some [fieldName] (unique) and [id] in request is not valid ObjectId then search by field with name [fieldName];app; // A basic error handler, just like Expressapp; app;console;
You can run this example by using npm start
and going to localhost:3030/messages. You should see an empty array. That's because you don't have any messages yet but you now have full CRUD for your new message service, including mongoose validations!