How to define array index to find data from specific key

const { Schema } = require(“ottoman”);
var schema = new Schema({
agentId: { type: String },
fname: { type: String },
lname: { type: String }
})

var schema = new Schema({
markupId: { type: String },
markupTitle: { type: String },
agent: [{ type: Agent, ref: “Agent” }]

});

schema.index.findByAgentIds = {
by: ‘agent[*].agentId’,
type: ‘refdoc’
};
module.exports = schema;

const result = await Markup.findByAgentIds(agents.id, options);

not get any data from the array. follow is the result which I got .

{

    "cause": {

        "code": 301

    },

    "context": {

        "status_code": 1,

        "opaque": 2,

        "cas": "0",

        "key": "$_defaultAgentMarkup$agent[*]::agentId.587145ec-a498-4c21-9123-0b937a6906d6",

        "bucket": "sampleTrucard",

        "collection": "",

        "scope": "",

        "context": "",

        "ref": ""

    }

}

please give me a suggestion, how I get data from the array index,

Hi @Nikhil_Bharambe refdoc doesnt support arrays .

If you want to query documents by the agentId within an array of agent objects, you will need to consider a different approach. One common approach is to use the Map-Reduce or N1QL query capabilities provided by Couchbase, depending on your use case.

Here’s a high-level outline of what you can do:

  1. You can create a Map-Reduce view that emits the agentId as the key and the document as the value. This way, you can query the view with the agentId to retrieve the associated documents. You will need to design your views and queries accordingly.
  2. You can use N1QL (Couchbase’s query language) to query the documents based on the values within the array. For example, you can write a query like:

SELECT * FROM your_bucket WHERE ANY agent IN agents SATISFIES agent.agentId = ‘your_agent_id’ END;

  1. Replace 'your_agent_id' with the specific agent ID you’re looking for.

Remember that these approaches might require a different lead enrichment structure or indexing strategy than what you have shown in your schema. You’ll need to design your data model and queries according to your specific requirements.

Additionally, please ensure that you have the necessary Couchbase server configurations, including indexes and buckets, set up correctly for your application to work as expected.