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

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);

`

Hello @Vigneshwaran_Rengana to add the fully qualified namespace you are correct use the qualifier like you have mentioned, if your keyspace has special characters than escape the name using the ticks

for instance

const query = new Query({}, 'bucketName.scopeName.collectionName');

I have also opened up a Github Issue to track this further. - Query Builder Question · Issue #639 · couchbaselabs/node-ottoman · GitHub

Can you please help for my first question also

Sure @Vigneshwaran_Rengana

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

Hello @Vigneshwaran_Rengana just following up to see if this helped ?