This Feathers service adapter is the same as the
feathers-mongoose adapter, but includes optimizations for handling bulk insertion of data.
With the current feathers-mongoose adapter, when you pass 100 items to
create and 1 or more have errors either with validation or write errors (duplicate
_id) you will only get back the first error and this will throw and skip any after hooks.
This plugin returns a success response when a record is inserted, but pushes errored records into
params.errors. You can handle those in an after hook at
hook.params.errors. Even with errors, the after hooks will be run as all the items with errors will be present in
This adapter drops support for Node.js V4.
npm install feathers-mongoose-advanced --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!