0

My document looks like

  "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 and mdblbahg4b17jdr82c3i keys are uniquely generate. I want is_deleted is equal to 1 result set. How can I find this result using mango query?

Lokesh Jain
  • 579
  • 6
  • 19
  • What is the storing your milestone with an object if you can't use the key for query? Atleast with an array, you would have been able to query it. The only solution i'm aware of is to use a view. – Alexis Côté Feb 17 '18 at 14:34
  • because of update milestone. I just wanted to create a unique id and based on that i wanted to update. Even I don't know the best design of document so that i can update also based on unique parameter. – Lokesh Jain Feb 19 '18 at 07:33

1 Answers1

0

if possible, you may consider storing each milestone in it own document (with your desired unique ID). for example, this would be silver

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

and this is would be gold

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

when creating the document you can specify the ID to use with PUT request:

PUT /{dbname}/{id}

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

after which, you can use mango to query the is_deleted documents you want:

{
  "selector":
  {
    "is_deleted": { "$eq": 1 }
  }
}
vabarbosa
  • 706
  • 1
  • 4
  • 9