Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deeply nested queries not working #77

Open
tomgosling2017 opened this issue Jul 20, 2017 · 1 comment
Open

Deeply nested queries not working #77

tomgosling2017 opened this issue Jul 20, 2017 · 1 comment

Comments

@tomgosling2017
Copy link

tomgosling2017 commented Jul 20, 2017

Trying to query works.boq.id (or any other field at that level) returns no results

db.search({
query: '1001',
fields: ['works.boq.id'],
include_docs: true
}).then(function(docs){
console.log(docs);

   });

Here's the json:

{"_id": "13bfce01-02ac-3994-bb1c-f90aa18ffc1c",
"_rev": "1-c989370c0b10d24b83a7c32d4200cf9d",
"id": 2,
"type": "contract",
"contract_name": "Enterprise-wide methodical infrastructure",
"ref": "578",
"address_1": "1202",
"address_2": "Taryn Ranch",
"address_3": "",
"address_4": "",
"town": "Stephaniemouth",
"county": "Massachusetts",
"postcode": "13032-0620",
"country": "Kyrgyz Republic",
"created_at": null,
"updated_at": null,
"deleted_at": null,
"works": [
{
"id": 101,
"_id": "bedfb0a8-fe0f-3993-9447-4317d0a73364",
"type": "works_instruction",
"contract_id": 2,
"scope_of_works": "Proactive discrete task-force",
"created_at": null,
"updated_at": null,
"deleted_at": null,
"boq": [
{
"id": 1001,
"_id": "ca9d7ab8-768e-3483-9480-6c0c756a6900",
"type": "boq_item",
"works_instruction_id": 101,
"item_name": "Compatible secondary toolset",
"quantity": 1,
"unit": "No.",
"rate": 311.3,
"total": 311.3,
"created_at": null,
"updated_at": null,
"deleted_at": null
},
},
}

@carloslfu
Copy link

Hello @tomgosling2017 this work only for deeply nested objects, in your case works and boq are arrays. Something like that works:

var document = {
  _id: 'mydoc',
  "type": "contract",
  "contract_name": "Enterprise-wide methodical infrastructure",
  "ref": "578",
  "address_1": "1202",
  "address_2": "Taryn Ranch",
  "address_3": "",
  "address_4": "",
  "town": "Stephaniemouth",
  "county": "Massachusetts",
  "postcode": "13032-0620",
  "country": "Kyrgyz Republic",
  "created_at": null,
  "updated_at": null,
  "deleted_at": null,
  "work": {
    "id": 101,
    "_id": "bedfb0a8-fe0f-3993-9447-4317d0a73364",
    "type": "works_instruction",
    "contract_id": 2,
    "scope_of_works": "Proactive discrete task-force",
    "created_at": null,
    "updated_at": null,
    "deleted_at": null,
    "boq": {
      "id": 1001,
      "_id": "ca9d7ab8-768e-3483-9480-6c0c756a6900",
      "type": "boq_item",
      "works_instruction_id": 101,
      "item_name": "Compatible secondary toolset",
      "quantity": 1,
      "unit": "No.",
      "rate": 311.3,
      "total": 311.3,
      "created_at": null,
      "updated_at": null,
      "deleted_at": null
    }, 
  },
}

DB.put(document).then(function (res) {

  DB.search({
    query: '1001',
    fields: ['work.boq.id'],
    include_docs: true,
  }).then(res => console.log(res.rows))

})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants