Node.js连接Marklogic调用documents.write()报404错误求助
Hey there! Let's break down why you're hitting that 404 error when trying to load documents into MarkLogic. This error usually means your Node.js app can't reach the right endpoint to write data, so here are the most likely fixes:
1. You're using the wrong port
Your my-connection.js is pointing to port 8001—that's MarkLogic's admin console port, meant for server configuration, user management, and other admin tasks. It's not the port you use for REST API operations like writing documents.
The default REST API port for MarkLogic is 8000. Update your connection file to use this port instead:
module.exports = { connInfo: { host: '127.0.0.1', port: 8000, user: 'user', password: 'password' } };
2. Ensure a REST API instance exists
If changing the port doesn't fix it, you might not have a REST API instance set up for your database. Here's how to check:
- Open the MarkLogic admin console at
http://127.0.0.1:8001 - Go to App Servers > REST API
- Make sure there's an instance bound to port
8000(or whatever port you're using in your code) that points to the database you want to write to (usually the defaultDocumentsdatabase) - If there's no instance, create one using the "Create REST API Instance" wizard in the admin console.
3. Verify your user has write permissions
Even if the endpoint is reachable, your user account might not have permission to write documents. Fix this by:
- In the admin console, go to Users and select your user
- Add the
rest-writerrole to their assigned roles (this role grants all necessary permissions for writing via the REST API) - Save the changes and try running your script again.
Bonus: Check MarkLogic logs for more details
If you're still stuck, take a look at MarkLogic's log files (usually located in your MarkLogic installation directory under Logs). The logs will have detailed error messages that can pinpoint exactly what's going wrong—like if the database doesn't exist, or the user lacks specific permissions.
Give these steps a try, and your sample script should load those documents without issues!
内容的提问来源于stack exchange,提问作者apelidoko

