Couchdb:使用 curl 从所有数据库中获取所有文档

Couchdb: Get all documents from all databases with curl

我需要将所有数据库中所有文档的内容保存在一个文件中。我知道我可以使用 curl:

从一个数据库中获取所有文档
curl -X GET http://localhost:5984/dbname/_all_docs?include_docs=true

我为所有数据库尝试这个:

curl -X GET http://localhost:5984/_all_dbs/_all_docs?include_docs=true

但是没用。

这样的脚本可能有效:

#!/bin/bash

string=$(curl -X GET http://localhost:5984/_all_dbs | sed 's/\[//' | sed 's/\]//' | sed 's/\"//g')

IFS=', ' read -a array <<< "$string"

for database in "${array[@]}"
do
    $(curl -X GET http://localhost:5984/$database/_all_docs?include_docs=true >> allData.txt)
done

这将向每个数据库发送一个对所有文档的请求并将结果附加到 allData.txt,您可能需要以某种方式将数据修复为您喜欢的格式,但您将拥有所有这些。

sed:s 从第一个 GET 请求中删除 []"