Ottoman Couchbase Join on find()

Does Couchbase support joins in the find method? I have 4 types of documents involved. I have the following N1QL query, and I am trying to apply it to my app using Ottoman.

SELECT l.type2array[*].`$ref`
FROM default k
UNNEST k.type3 l
UNNEST l.type2array j
LEFT JOIN default a
ON KEYS ["Type1|" || l.type1.`$ref`]
LEFT JOIN default m
ON KEYS ["Type2|" || l.type2array[*].`$ref`]
WHERE k._type = "Type3"
AND k.`user`.`$ref` = id
AND UPPER(a.name) LIKE UPPER("%keyword%")

Is there a way to adapt this to Ottoman? If not, how should I go about adapting this for my Node application?

Hey @johanna,

Ottoman.js does not support executing JOIN queries, N1QL itself of course does (as you have demonstrated). You’re best bet would be to perform these kinds of queries externally from Ottoman.js, and then if you need to, you can instantiate Ottoman object instances based on the data you have queries.

Out of separate curiosity, can you explain a little bit about your use-case for performing the joins?

Cheers, Brett

Oh, I guess I’ll have to do it that way then, thanks! Is this something Ottoman.js is planning to support in the future?’

I have the following model:

var type1= ottoman.model("Type1", {
    created : { type: "Date", default: Date.now() },
    user : { ref : "User" },
    connections: [{
        type2: { ref : "Type2" },
        type3: [{ ref: "Type3" }],
        count : "integer"
    }]
}

Basically I am trying to do a search by keyword. I have to check whether the keyword searched for is in the name of a Type3 document contained in the array, or is of a certain Type2, but since references only have the type and id, I have to perform some join operations to get the name before checking.

Thanks again!