繁体   English   中英

MongoDB Atlas触发器—收到“ StitchError:HTTP请求失败:意外状态代码:预期= 200,实际= 415”错误

[英]MongoDB Atlas Trigger — Receiving a “StitchError: HTTP request failed: unexpected status code: expected=200, actual=415” error

我们正在尝试在MongoDB Atlas中创建一个触发器,该触发器将自动减少晚上的Azure层以节省成本。 当我们尝试运行它时,我们放在一起的函数(可能不正确!)返回错误。 结果输出为:

logs: 
uncaught promise rejection: StitchError: HTTP request failed: unexpected status code: expected=200, actual=415
> result: 
{
  "$undefined": true
}
> result (JavaScript): 
EJSON.parse('{"$undefined":true}')

我们尝试弄乱标题和正文,但最终结果始终相同。

这是WIP功能:

exports = function() {

  const response = context.http.patch({
    scheme: "https",
    host: "cloud.mongodb.com",
    path: "/api/atlas/v1.0/groups/abc123/clusters/fake-server",
    username: "usernamehere",
    password: "passwordhere",
    digestAuth: true,
    headers: {"Content-Type": [ "application/json" ]},
    body: {"clusterType":"REPLICASET", "providerSettings":{"providerName":"AZURE", "instanceSizeName":"M10", "regionName":"regionhere" } },
    encodeBodyAsJSON: true
  });
};

任何帮助将不胜感激。

事实证明,我们一直都对。

执行与上面完全相同的代码现在可以正确地减少我们的层级。 我不知道是什么原因导致MongoDB Atlas API认为我们的标头和/或请求正文不正确,但是今天对此感到非常满意。

我要指出的唯一一件事是,如果您希望错误的这一部分消失……

> result: 
{
  "$undefined": true
}
> result (JavaScript): 
EJSON.parse('{"$undefined":true}')

...您需要将功能更改为异步/等待,如下所示:

exports = async function() {

  const response = await context.http.patch({ 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM