在唯一生成的文档中搜索(CouchDb)

时间:2018-02-17 11:49:04

标签: couchdb couchdb-mango

我的文档看起来像

  "milestone": {
    "afyyjahg4a9cjdr7056s": {
      "milestone_name": "Silver",
      "milestone_desc": "this is silver milestone",
      "target": 100,
      "reward_value": 100,
      "is_deleted": 1
    },
    "mdblbahg4b17jdr82c3i": {
      "milestone_name": "Gold",
      "milestone_desc": "this is gold milestone",
      "target": 200,
      "reward_value": 250,
      "is_deleted": 0
    }
  }

afyyjahg4a9cjdr7056s和mdblbahg4b17jdr82c3i密钥是唯一生成的。我想is_deleted等于1个结果集。如何使用芒果查询找到这个结果?

1 个答案:

答案 0 :(得分:0)

如果可能,您可以考虑将每个里程碑存储在自己的文档中(使用您所需的唯一ID)。例如,这将是银

{
    "_id": "afyyjahg4a9cjdr7056s",
    "type": "milestone"
    "name": "Silver",
    "desc": "this is silver milestone",
    "target": 100,
    "reward_value": 100,
    "is_deleted": 1
}

这将是黄金

{
    "_id": "mdblbahg4b17jdr82c3i",
    "type": "milestone"
    "name": "Gold",
    "desc": "this is gold milestone",
    "target": 200,
    "reward_value": 250,
    "is_deleted": 0
}

创建文档时,您可以指定用于PUT请求的ID:

PUT /{dbname}/{id}

请参阅:http://docs.couchdb.org/en/2.0.0/api/document/common.html#put--db-docid

之后,您可以使用芒果查询所需的is_deleted文档:

{
  "selector":
  {
    "is_deleted": { "$eq": 1 }
  }
}