英文:
CURL Script for "Map From Data Services" functionality in Couchabase analytics
问题
我正在尝试使用CURL创建一个脚本,将数据服务中存储桶范围内的所有集合映射到本地的分析服务(Couchbase)。
我在我的数据节点中创建了大约50个集合,现在我需要它们在我的分析节点中(本地,没有远程链接)。
如果有人已经完成了这个任务,请提供建议。
附注:不需要ChatGPT的答案,已经尝试过它们,但没有成功。
已经尝试过CBQ命令、CLI命令和CURL命令,但都没有成功。
希望能够通过以上任何一种方式实现相同的目标。
英文:
I am trying to create a script using CURL to map all collections present in a bucket.scope from data service to analytical service locally (Couchbase).
I have 50 odd collections created in my data node and now i need them in my analytics node (locally , no remote links).
suggest if any one has already done this.
P.S, No ChatGPT answers, tried them all not working.
Tried CBQ Commands, CLI commands, CURL commands. No Luck.
Hoping to acheive the same with any of the above.
答案1
得分: 1
I'm not sure if there is a way to do this with a single cURL command, but you could do this with a series of cURL commands orchestrated in a small bash script such as the example below:
#!/bin/bash
USERNAME=administrator
PASSWORD=password
COUCHBASE_HOST=http://127.0.0.1:8091
ANALYTICS_HOST=http://127.0.0.1:8095
BUCKET=$1
SCOPE=$2
if [ $# != 2 ]; then
echo Usage: $0 <bucket> <scope>
exit 1
fi
run_analytics () {
echo Running "$*"
curl -s -u $USERNAME:$PASSWORD $ANALYTICS_HOST/analytics/service -d statement="$*" | jq '.errors[].msg' 2>/dev/null
}
echo Mapping $BUCKET.$SCOPE in Analytics
run_analytics CREATE ANALYTICS SCOPE `$BUCKET`.`$SCOPE` IF NOT EXISTS
run_analytics DISCONNECT LINK `$BUCKET`.`$SCOPE`.Local
for collection in $(curl -s -u $USERNAME:$PASSWORD $COUCHBASE_HOST/pools/default/buckets/$BUCKET/scopes | jq -r ".scopes[] | select(.name == \"$SCOPE\") | .collections[].name"); do
run_analytics ALTER COLLECTION `$BUCKET`.`$SCOPE`.`$collection` ENABLE ANALYTICS
done
run_analytics CONNECT LINK `$BUCKET`.`$SCOPE`.Local
Note that there's no error handling, handling of funky bucket characters that would require URL encoding, etc. but hopefully this helps...
英文:
I'm not sure if there is a way to do this with a single cURL command, but you could do this with series of cURL commands orchestrated in a small bash script such as the example below:
#!/bin/bash
USERNAME=administrator
PASSWORD=password
COUCHBASE_HOST=http://127.0.0.1:8091
ANALYTICS_HOST=http://127.0.0.1:8095
BUCKET=$1
SCOPE=$2
if [ $# != 2 ]; then
echo Usage: $0 \<bucket\> \<scope\>
exit 1
fi
run_analytics () {
echo Running "$*"
curl -s -u $USERNAME:$PASSWORD $ANALYTICS_HOST/analytics/service -d statement="$*" | jq '.errors[].msg' 2>/dev/null
}
echo Mapping $BUCKET.$SCOPE in Analytics
run_analytics CREATE ANALYTICS SCOPE \`$BUCKET\`.\`$SCOPE\` IF NOT EXISTS
run_analytics DISCONNECT LINK \`$BUCKET\`.\`$SCOPE\`.Local
for collection in $(curl -s -u $USERNAME:$PASSWORD $COUCHBASE_HOST/pools/default/buckets/$BUCKET/scopes | jq -r ".scopes[] | select(.name == \"$SCOPE\") | .collections[].name"); do
run_analytics ALTER COLLECTION \`$BUCKET\`.\`$SCOPE\`.\`$collection\` ENABLE ANALYTICS
done
run_analytics CONNECT LINK \`$BUCKET\`.\`$SCOPE\`.Local
Note that there's no error handling, handling of funky bucket characters that would require URL encoding, etc. but hopefully this helps...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论