如何在CouchDB中从巨大的JSON文件(460MB)进行大容量插入
我需要在我的CouchDB数据库中批量插入文档。 我在这里尝试按照手册操作: 这是我的剧本:如何在CouchDB中从巨大的JSON文件(460MB)进行大容量插入,json,couchdb,bulkinsert,Json,Couchdb,Bulkinsert,我需要在我的CouchDB数据库中批量插入文档。 我在这里尝试按照手册操作: 这是我的剧本: ~$ DB="http://localhost:5984/employees" ~$ curl -H "Content-Type:application/json" -d @employees_selfContained.json -vX POST $DB/_bulk_docs employees_selfContained.json文件是一个大文件,大小为465 MB。我已经使用JSONLint对其
~$ DB="http://localhost:5984/employees"
~$ curl -H "Content-Type:application/json" -d @employees_selfContained.json -vX POST $DB/_bulk_docs
employees_selfContained.json文件是一个大文件,大小为465 MB。我已经使用JSONLint对其进行了验证,没有发现任何错误
下面是curl的详细输出:
* About to connect() to 127.0.0.1 port 5984 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 5984 (#0)
> POST /employees/_bulk_docs HTTP/1.1
> User-Agent: curl/7.19.7 (i486-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: 127.0.0.1:5984
> Accept: */*
> Content-Type:application/json
> Content-Length: 439203931
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server
* Closing connection #0
循环JSON并批量插入10-50k文档。您能检查CouchDB日志中是否出现任何内容吗?否。没有任何迹象表明批量文档插入成功。我尝试过使用较小的JSON文件(4K),但它运行成功。您可能希望使用编写一个小的Node.js脚本,以便您可以将文档排队,以便以较小的批进行批量插入,同时仍保持文件完整。460MB大?我目前正在尝试将一个30 GB导出的couchdb Json文件导入到另一个实例中。哈哈。是的,正如答案所说,你必须把它分开。我使用GoLang的bufio.Scanner来完成这项工作。这是否意味着我必须拆分包含10-50k文档的较小文件?我可以批量插入那个大文件吗?好的。我将此文档拆分为每个文档10-50k。为什么它必须在10-50k之间,有什么特别的原因吗?谢谢你的帮助@ShahrizalPrabowo我要把这个从。。。但是我认为如果post/put操作需要很长时间并且失败,HTTP接口将超时。所以我认为这是一个时间问题。
{
"docs": [
{
"emp_no": ..,
"birth_date": ..,
"first_name": ..,
"last_name" : ..,
"gender": ..,
"hire_date": ..,
"titles":
[
{
"title": ..,
"from_date": ..,
"to_date": ..
},
{..}
],
"salaries" :
[
{
"salary": ..,
"from_date": ..,
"to_date": ..
},
{..}
],
"dept_emp":
[
{
"dept_no": ..,
"from_date": ..,
"to_date":
},
{..}
],
"dept_manager":
[
{
"dept_no": ..,
"from_date": ..,
"to_date": ..
},
{..}
],
"departments":
[
{
"dept_no": ..,
"dept_name": ..
},
{..}
]
} ,
.
.
{..}
]
}