如何 select couchbase 中的文档按其他 id 字段过滤?

How to select documents in couchbase filtered by a field other id?

我的存储桶中有包含架构的文档:

{
  "status": "done",
  "id": 1
}

我想 select 所有 statusdone 的文档。

假设您使用的是 Couchbase Server 4.x 或更高版本,您可以使用 N1QL 查询来执行此操作。例如:

SELECT d.*
FROM mydocuments d
WHERE d.status == 'done'

您还需要在 status 上创建一个索引(至少创建索引比 Whosebug 的答案所能提供的要复杂得多),如下所示:

CREATE INDEX ix_status ON mydocuments (status);

有关详细信息,请查看 N1QL documentation and the interactive N1QL tutorial