cbimport 不导入从 cbq 命令中提取的文件

cbimport not importing file which is extracted from cbq command

我尝试从下面的 cbq 命令中提取数据,结果成功了。

cbq -u Administrator -p Administrator -e "http://localhost:8093" --script= SELECT * FROM `sample` where customer.id=="12345'" -q | jq '.results' > temp.json;

但是,当我尝试使用以下命令将 json 格式的相同数据导入到目标集群时,出现错误。

cbimport json -c http://{target-cluster}:8091 -u Administrator -p Administrator -b sample -d file://C:\Users\{myusername}\Desktop\temp.json -f list -g %docId%

JSON import failed: 0 documents were imported, 0 documents failed to be imported
JSON import failed: input json is invalid: ReadArray: expect [ or , or ] or n, but found {, error found in #1 byte of ...|{
    "requ|..., bigger context ...|{
    "requestID": "2fc34542-4387-4643-8ae3-914e316|...],```

    ```{
    "requestID": "6ef38b8a-8e70-4c3d-b3b4-b73518a09c62",
    "signature": {
        "*": "*"
    },
    "results": [
    {
        "{Bucket-name}":{my-data}
    "status": "success",
    "metrics": {
        "elapsedTime": "4.517031ms",
        "executionTime": "4.365976ms",
        "resultCount": 1,
        "resultSize": 24926
    }

看起来从 cbq 命令中提取的文件具有控制字段详细信息,例如 RequestID、指标、状态等 。也 json 以漂亮的格式。如果我手动删除它(删除除 {my-data} 之外的所有字段),然后放入一个 json 文件并使 json 不漂亮,然后它就可以工作了。但我想在一个 运行 中将其自动化。有没有办法在 cbq 命令.

中做到这一点

我找不到任何其他实用程序或方法可以轻松地在 cbexport to do that on Couchbase, because the document which are exported using cbexport can be imported using cbimport 上使用 where 条件。

对于 cbq 命令,您可以使用 --quiet 选项禁用启动连接消息,使用 --pretty=false 禁用漂亮打印。然后,为了仅提取 cbimport json 行格式的文档,我使用了 jq.

这对我有用——从旅行中选择文档-sample._default._default(对于 jq 过滤器,我有 _default,你可以根据你的例子放置 Bucket-name):

cbq --quiet --pretty=false -u Administrator -p password --script='select * from `travel-sample`._default._default' | jq --compact-output '.results|.[]|._default' > docs.json

然后,导入test-bucket1:

cbimport json -c localhost -u Administrator -p password -b test-bucket1 -d file://./docs.json -f lines -g %type%_%id%

cbq 文档:https://docs.couchbase.com/server/current/tools/cbq-shell.html

cbimport 文档:https://docs.couchbase.com/server/current/tools/cbimport-json.html

jq 文档: https://stedolan.github.io/jq/manual/#Basicfilters