node.js - “RESTAPI-INVALIDREQ:(错误:FOER0000)无效请求:原因:uri urlList.json 的无效补丁:无效路径:/test/
问题描述
我有一个名为 urlList.json 的带有以下 JSON 文档的 marklogic 数据库
{
"test": {
"ip": "10.10.10.10",
"fqdn": "www.test.test"
}
}
我正在尝试使用补丁添加到带有 marklogic rest API 的测试对象。我正在使用带有 request-promise 模块的 Node 这是代码
var options = {
method: 'PATCH',
url: 'https://test:8000/v1/documents',
qs: { database: databaseName, uri: 'urlList.json' },
headers:
{
'Content-Type': 'application/json',
Accept: 'application/json'
},
strictSSL: false,
auth: {
user: userName,
pass: password,
sendImmediately: false
},
body: JSON.stringify({
"patch": [
{
"insert": {
"context": "/test/",
"position": "last-child",
"content": { "test": "test"}
}
}
]
})
};
request(options)
.then(results => {
return resolve(results);
})
.catch(err => {
return reject(err);
})
运行时的期望结果是
{
"test": {
"ip": "10.10.10.10",
"fqdn": "www.test.test",
"test": "test"
}
}
每次运行时都会出现以下错误
"400 - "{\"errorResponse\":{\"statusCode\":400, \"status\":\"Bad
Request\", \"messageCode\":\"RESTAPI-INVALIDREQ\",
\"message\":\"RESTAPI-INVALIDREQ: (err:FOER0000) Invalid request:
reason: invalid patch for uri urlList.json: invalid path: /test/\"}}""
这是发送的正文
"{"patch":[{"insert":{"context":"/test/","position":"last-
child","content":{"test":"test"}}}]}"
解决方案
路径必须选择一个节点。因此,路径不能以分隔符结尾。这就是信息试图传达的内容。
它适用于路径/test
吗?
顺便说一句,MarkLogic 提供了一个支持 Promise 的 Node.js API。这可能更容易使用。
希望有帮助,
推荐阅读
- android - 单击TextView(设置为可聚焦)后如何在android上隐藏软键盘?
- java - 将字符串数组添加到 MongoDB 中的 ProjectionOperation
- puppeteer - 如何构建 puppeteer 表单源
- perl - 如何在perl中忽略哈希的键序列
- apache-spark - 当我们需要 Spark 进行大数据处理的动作操作时,提高速度的关键是什么?
- html - 博主soho主题:如何修改跳转链接按钮的功能?
- html - 无法定位我的边界
- python - 填充 NAN 并转换为 int pandas
- c# - XmlReader 在读取时解析 DTD 实体,可以禁用吗?
- data-structures - 使用二叉搜索树(展开树)实现绳索数据结构