npm install feathers-mongoose --save
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 and Sorting - How to use pagination and sorting for the database adapter
- Querying - The common adapter querying mechanism
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.
Here's a complete example of a Feathers server with a
const feathers = ;const rest = ;const socketio = ;const errors = ;const bodyParser = ;const mongoose = ;const service = ;// Require your modelsconst Message = ;// Tell mongoose to use native promises// SeemongoosePromise = 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;// 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!