Skip to content

Commit 957462e

Browse files
committed
adding migration docs
1 parent 8d4ab77 commit 957462e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,31 @@ app.use('/todos', myService);
219219
**Note:** _this is more for backwards compatibility. We recommend the usage of hooks as they are easier to test, easier to maintain and are more flexible._
220220

221221

222+
## Migrating
223+
224+
Version 3 of this adapter no longer brings its own Mongoose dependency, only accepts mongoose models and doesn't set up a database connection for you anymore. This means that you now need to make your own mongoose database connection and you need to pass in mongoose models changing something like
225+
226+
```js
227+
var MySchema = require('./models/mymodel')
228+
var mongooseService = require('feathers-mongoose');
229+
app.use('todos', mongooseService('todo', MySchema, options));
230+
```
231+
232+
To
233+
234+
```js
235+
var mongoose = require('mongoose');
236+
var MongooseModel = require('./models/mymodel')
237+
var mongooseService = require('feathers-mongoose');
238+
239+
mongoose.Promise = global.Promise;
240+
mongoose.connect('mongodb://localhost:27017/feathers');
241+
242+
app.use('/todos', mongooseService({
243+
Model: MongooseModel
244+
}));
245+
```
246+
222247
## Validation
223248

224249
Mongoose by default gives you the ability to add [validations at the model level](http://mongoosejs.com/docs/validation.html). Using an error handler like the [middleware that comes with Feathers](https://github.com/feathersjs/generator-feathers/blob/master/app/templates/src/middleware/error-handler.js) your validation errors will be formatted nicely right out of the box!

0 commit comments

Comments
 (0)