2

我正在尝试在单个字段中更新 mongodb 文档,我怀疑我想使用哪种方法来使用补丁或使用羽毛框架进行更新,请举例说明我们如何做到这一点。

const { authenticate } = require('feathers-authentication').hooks;

module.exports = {
  before: {
    all: [ authenticate('jwt') ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  after: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  error: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
};
4

1 回答 1

2

update将替换整个文档。patch应使用与现有数据合并。这在此处此处通过以下示例进行了记录:

app.service('messages').patch(1, {
  text: 'A patched message'
}).then(message => console.log(message));

const params = {
  query: { read: false }
};

// Mark all unread messages as read
app.service('messages').patch(null, {
  read: true
}, params);
于 2017-12-16T19:52:13.750 回答