【问题标题】:@ibm-cloud/cloudant: includeDocs: true, still not able to get the entire details of the documents@ibm-cloud/cloudant:includeDocs:是的,仍然无法获取文档的全部详细信息
【发布时间】:2022-01-17 03:08:37
【问题描述】:

service.postAllDocs({ db: '订单', 包括文档:真, 限制:10 }).then(response => { console.log(response.result)});

结果只返回: id、key、value(只包含rev)

【问题讨论】:

    标签: websphere cloudant


    【解决方案1】:

    要从数据库中获取前 10 个文档,包括文档正文,此代码有效:

    const { CloudantV1 } = require('@ibm-cloud/cloudant')
    const client = CloudantV1.newInstance()
    const DBNAME = 'orders'
    
    const main = async function () {
        const response = await client.postAllDocs({ db: DBNAME, includeDocs: true, limit: 10 })
        console.log(response.result.rows)
    }
    
    
    main()
    

    这会产生以下输出:

    [
      {
        id: '1',
        key: '1',
        value: { rev: '1-0fdc08a2625917344e37eb91661a5568' },
        doc: {
          _id: '1',
          _rev: '1-0fdc08a2625917344e37eb91661a5568',
          fruit: 'banana'
        }
      },
      {
        id: '2',
        key: '2',
        value: { rev: '1-8c4d4385540143ea87f8663193105425' },
        doc: {
          _id: '2',
          _rev: '1-8c4d4385540143ea87f8663193105425',
          fruit: 'apple'
        }
      }
    ]
    

    文档正文位于每个对象的doc 属性下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-11
      • 1970-01-01
      • 2021-01-01
      • 1970-01-01
      • 2020-01-30
      相关资源
      最近更新 更多