【问题标题】:Can I POST multiple patch requests to RavenDB's /bulk_docs HTTP API endpoint?我可以向 RavenDB 的 /bulk_docs HTTP API 端点发布多个补丁请求吗?
【发布时间】:2015-04-24 22:00:56
【问题描述】:

我正在为 RavenDB 编写节点包装器。

我使用的是版本 3,但由于没有 HTTP 文档,我一直依赖 2.0 和 2.5 文档。

关于单个文档的操作,我已经成功地将this doc page 用于单个文档的 PUT、DELETE 和多个 PATCH。

同样,我在一次 HTTP 调用中成功地使用了this doc page 对多个文档的多个 PUT 和 DELETE 操作但在一次调用中 PATCHing 多个文档方面的文档有点模糊

在“批处理请求”标题下,它清楚地表明这是可能的:

RavenDB 中的请求批处理是使用“/bulk_docs”端点处理的,该端点接受要执行的操作数组。操作格式为:

方法 - PUT、PATCH 或 DELETE。

...

对于 PUT,我 POST 到 /bulk_docs:

[
  {
    Method: 'PUT',
    Key: 'users/1',
    Document: { username: 'dummy' }
    Metadata: { 'Raven-Entity-Type': 'Users' }
  },
  ...
]

对于 DELETE,我 POST 到 /bulk_docs:

[
  {
    Method: 'DELETE',
    Key: 'users/1'
  },
  ...
]

对于补丁,我尝试发布以下内容,但没有任何运气:

[
  {
    Method: 'PATCH',
    Key: 'users/1',
    Document: {
      Type: 'Set',
      Name:'username',
      Value: 'new-username'
    }
  },
  ...
]

[
  {
    Method: 'PATCH',
    Key: 'users/1',
    Type: 'Set',
    Name:'username',
    Value: 'new-username'
  },
  ...
]

我得到的只是500 - Internal Server Error,并且没有任何在该文档页面上修补多个文档的示例,我有点卡住了......

任何帮助将不胜感激:)

【问题讨论】:

    标签: ravendb ravendb-http


    【解决方案1】:

    PATCH 的结构是:

    [
      {
        Method: 'PATCH',
        Key: 'users/1',
        Patches: [{
    Type: 'Set',
            Name:'username',
            Value: 'new-username'
    }]
      },
      ...
    ]
    

    完整的结构可以在这里看到: https://github.com/ayende/ravendb/blob/master/Raven.Abstractions/Commands/PatchCommandData.cs#L72

    【讨论】:

    • 谢谢@Ayende。我昨晚深夜浏览了源代码并弄明白了。以后我会尝试更频繁地使用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    • 2017-05-05
    • 1970-01-01
    • 2015-09-15
    • 2021-10-31
    • 2020-05-21
    • 1970-01-01
    相关资源
    最近更新 更多