question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query Builder Question

See original GitHub issue

How to query a field inside array sub-document using ottoman query builder? How to add Collection name and scope name to query builder?`

import { Schema, Query, getDefaultInstance } from "ottoman";

const  TestSchema = new Schema({
block1:{
    field1:{type: String, required: true},
    field2:{type: String, required: true}
},
block2:[{
    field3:{type: String, required: true},
    field4:{type: String, required: true}
}]
})

const ottoman = getDefaultInstance();
const query = new Query({}, 'bucketName.scopeName.collectionName');
const where_exp = {block2[{field3}]:{$eq: 'xyz'}};
const result = query
  .select()
  .where(where_exp)
  .build();
console.log(result);

Source : forum post - https://forums.couchbase.com/t/how-to-query-a-field-inside-array-sub-document-using-ottoman-query-builder-how-to-add-collection-name-and-scope-name-to-query-builder/32978

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AV25242commented, Mar 7, 2022

Thanks

0reactions
gsi-alejandrocommented, Mar 7, 2022

To query into array values use this way:

const where_exp = {
      $any: {
          $expr: [{ b: { $in: 'block2' } }],
          $satisfies: { 'b.field3': {$eq: "xyz"} },
      }
  };

this will produce this valid N1Ql query SELECT * FROM `travel-sample`.`inventory`.`hotel` WHERE ANY b IN block2 SATISFIES b.field3="xyz" END

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query builder - Metabase
Create your question from scratch using the query builder interface. The query builder offers more flexibility for constructing a question: in addition to...
Read more >
Newest 'query-builder' Questions - Stack Overflow
I am tring to trigger an event to save doctype data based on another doctype. This is how my doctype are: Employee has...
Read more >
querybuilder basic question - Experience League Community
Answer to your queries inline in bold. Questions: None of the results are actually pages from the site? The site we have locally...
Read more >
Questions and issues | laravel-query-builder - Spatie
Introduction · Requirements · About us ; Filtering · Sorting · Including relationships ; Extending query builder · Pagination · Front-end implementation ...
Read more >
Frequently asked questions (FAQ) - Query Builder - Eurostat
Frequently asked questions (FAQ) - Query Builder · Query Builder · Frequently asked questions (FAQ) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found