如何查找缺少字段的 Cloudant 记录

How to find a Cloudant record missing a field

我有一个数据库,其中的记录如下所示

{
  "_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 分钟

在 Cloudant 仪表板中,单击新建视图并添加一个 "map" 函数,如下所示

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

Cloudant 将通过此功能提供数据库中的所有文档。任何缺少 'appId' 属性 的内容都将形成一个包含文档 ID 和 'null' 的索引。索引建立后(几秒钟),您应该会在 window.

的右侧看到任何缺少 ID 的文档

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