【问题标题】:How to find a Cloudant record missing a field如何查找缺少字段的 Cloudant 记录
【发布时间】:2016-10-25 19:06:32
【问题描述】:

我有一个数据库,其中的记录看起来像这样

{
  "_id": "eaed1a721cd763c68f7db76862cbf2c1",
  "_rev": "4-2f99dc06018a72af40143b47f0825aaa",
  "categorisationComments": "null",
  "description": "A mobile image-, video-sharing and social network service",
  "appName": "Instagram",
  "baseUrl": "instagram.com",
  "appId": 67,
  "currentStatus": 3,
  "primaryCategory": "Social Media"
}

我遇到的问题是,其中大约有 7000 个,并且使用 Python 和 couchdb 需要很长时间才能通读它们。 当我加载数据时, appId 被分配了一个值(完全没有理由) -1 ;这是一个糟糕的选择。 因为这是我的 Python 脚本卡住了

if doc['appId'] == -1: KeyError: 'appId'

所以,我似乎有一条缺少 appId 字段的记录。

如何创建 Cloudant 查询或 couchdb 搜索来查找我的任性记录?我真正想要的是查询,因为 couchdb 读取每一行大约需要 30 分钟

【问题讨论】:

    标签: python python-3.x couchdb cloudant


    【解决方案1】:

    在 Cloudant 仪表板中,单击“新建视图”并像这样添加“地图”功能

    function(doc) {
      if (typeof doc.appId === 'undefined') {
        emit(doc._id, null);
      }
    }
    

    Cloudant 将通过此功能提供数据库中的所有文档。任何缺少“appId”属性的人都将形成一个包含文档 id 和“null”的索引。建立索引后(几秒钟),您应该会在窗口右侧看到所有缺少 id 的文档。

    有关在 Cloudant 中创建 MapReduce 视图的更多详细信息,请参阅 https://docs.cloudant.com/creating_views.html。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 2017-05-06
      • 2018-04-16
      • 1970-01-01
      相关资源
      最近更新 更多