本文介绍了NODEJS Marklogic-使用document.write()时,写入文档列表无法处理状态为404的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to nodejs and marklogic, and I'm following a tutorial for a simple app, I have setup and configured my marklogin login credentials,

当我通过运行node sample.js

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

我想知道为什么会遇到此错误,

I wonder why I'm encountering this error,

这是教程中的代码,

my-connection.js

my-connection.js

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

sample.js

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));
}
);

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

I hope someone can tell me what is wrong with the code,

谢谢!

推荐答案

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

The MarkLogic NodeJS Client library is meant to run against a so-called MarkLogic REST-api instance. There is typically one running at port 8000, but you can also deploy other ones at different ports by issuing a POST call to :8002/v1/rest-apis, as described here:

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

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

Port 8001 however is reserved for the MarkLogic Admin UI, which doesn't understand the REST calls that the NodeJS Client library is trying to invoke, hence the 404 (not found)..

HTH!

这篇关于NODEJS Marklogic-使用document.write()时,写入文档列表无法处理状态为404的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 08:24