You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Rest API导出Orient DB(2.2.x)数据库架构及数据?

Exporting OrientDB 2.2.x (Schema + Data) via HTTP API

Hey there! Let's walk through how to get a complete export of your demo2 database—including both schema and all your data—using OrientDB 2.2.x's HTTP API. Here are the key steps and tweaks to make this work smoothly:

1. Update Your GET Request with Critical Parameters

Your initial request is a good start, but you need to add parameters to ensure data is included alongside the schema. Here's the adjusted request:

GET http://localhost:2480/export/demo2?includeRecords=true&includeSchema=true&format=json

Let's break down what each parameter does:

  • includeRecords=true: This forces the export to pull in all your database records (documents, vertices, edges—everything stored in your classes)
  • includeSchema=true: Explicitly ensures the export includes class definitions, properties, indexes, and other schema details (while this is often enabled by default, setting it explicitly avoids any unexpected omissions)
  • format: Choose your output format. json is great for readability and manual edits, odb is a binary format optimized for fast imports, and xml is another option if you need it for specific workflows.

2. Don't Skip Authentication

OrientDB's HTTP API requires valid credentials unless you've disabled security (which is not recommended for production). You have two main options:

  • Basic Auth: Add an Authorization header to your request. Encode your username:password as Base64, then use:
    Authorization: Basic <base64-encoded-credentials>
    
    For example, if your username is admin and password is admin, the encoded string is YWRtaW46YWRtaW4=, so the header becomes Authorization: Basic YWRtaW46YWRtaW4=.
  • Session Auth: First send a POST request to http://localhost:2480/session with your credentials to get a session ID, then include a Cookie header in your export request:
    Cookie: OSESSIONID=<your-session-id>
    

3. Handle Large Databases Gracefully

If your demo2 database is large, you might run into timeouts or memory issues. Fix this with:

  • batchSize=1000: Add this parameter to export records in smaller batches (adjust the number based on your database size)
  • Enable streaming downloads in your HTTP client: This prevents your client from trying to load the entire export file into memory at once.

4. Verify Your Export Worked

After the export completes, double-check the output to make sure everything is included:

  • For JSON/XML exports: Open the file and confirm you see a schema section (with class definitions) followed by a records section (with your data entries)
  • For ODB exports: Test the import using OrientDB's console tool. Run console.sh (or console.bat on Windows), then execute:
    import database /path/to/your/export.odb
    
    This will confirm the schema and data are intact.

5. Troubleshooting Common Snags

  • 401 Unauthorized: Double-check your credentials and make sure your user has the EXPORT permission (the default admin user has this by default)
  • 404 Not Found: Confirm the database name demo2 is spelled correctly and that the database is running in your OrientDB server
  • Empty Export: Ensure you added includeRecords=true—without it, you'll only get the schema. Also, check that your database actually has data to export!
  • Request Timeout: Increase the network.http.maxLength setting in your orientdb-server-config.xml file to allow larger payloads, or use the batchSize parameter to split the export into chunks.

内容的提问来源于stack exchange,提问作者BonieZat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:22:54