NODEJS Marklogic - 使用documents.write()时,写入文档列表无法处理404状态的响应

时间:2018-01-03 09:39:56

标签: node.js marklogic

我是nodejs和marklogic的新手,我正在关注一个简​​单应用的教程,我已经设置并配置了我的marklogin登录凭证,

当我通过运行node sample.js

运行此示例代码时

输出为write document list cannot process response with 404 status

我想知道为什么我遇到这个错误,

这是教程中的代码,

MY-connection.js

module.exports = {
    connInfo: {
    host: '127.0.0.1',
    port: 8001,
    user: 'user',
    password: 'password'
    }
};

sample.js

const marklogic = require('marklogic');
const my = require('./my-connection.js');
const db = marklogic.createDatabaseClient(my.connInfo);
const documents = [
{ uri: '/gs/aardvark.json',
   content: {
    name: 'aardvark',
    kind: 'mammal',
    desc: 'The aardvark is a medium-sized burrowing, nocturnal mammal.'
   }
},
{ uri: '/gs/bluebird.json',
   content: {
    name: 'bluebird',
    kind: 'bird',
    desc: 'The bluebird is a medium-sized, mostly insectivorous bird.'
   }
},
 { uri: '/gs/cobra.json',
  content: { 
    name: 'cobra',
    kind: 'mammal',
    desc: 'The cobra is a venomous, hooded snake of the family Elapidae.'
  }
 },
];

db.documents.write(documents).result(
function(response) {
 console.log('Loaded the following documents:');
 response.documents.forEach( function(document) {
  console.log(' ' + document.uri);
 });
},
function(error) {
 console.log('error here');
 console.log(JSON.stringify(error, null, 2));
}
);

我希望有人能告诉我代码有什么问题,

谢谢!

1 个答案:

答案 0 :(得分:1)

MarkLogic NodeJS客户端库旨在针对所谓的MarkLogic REST-api实例运行。通常有一个在端口8000上运行,但您也可以通过发出POST调用来在不同的端口部署其他端口:8002 / v1 / rest-apis,如下所述:

http://docs.marklogic.com/REST/POST/v1/rest-apis

端口8001是为MarkLogic Admin UI保留的,它不理解NodeJS客户端库试图调用的REST调用,因此404(未找到)..

HTH!