0.5.2 • Published 7 years ago

feathers-rename-id v0.5.2

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

feathers-rename-id

Build Status Greenkeeper badge

Can change "_id" to "id" for all requests.

Configure

const mongooseService = require('feathers-mongoose').Service;
const Service = require('feathers-rename-id')(mongooseService);
const Post = require('./post-model');

module.exports = function() {
  const app = this;
  
  app.use('/posts', new Service({
    Model: Post,
    newIdName: 'id' // Default value - 'id'
  }));
};

Usage

const post = await app.service('/posts').create({ id, text });
const got = await app.service('/posts').get(post.id);
const found = await app.service('/posts').find({ query: { id: post.id } });
const patched = await app.service('/posts').patch(null, { text }, { query: { id: post.id } });
const updated = await app.service('/posts').update(null, { text }, { query: { id: post.id } });
const removed = await app.service('/posts').remove(null, { query: { id: post.id } });