Ottoman query based on attribute of object reference


I have 3 models, A, B and C. C has a single reference to A, and an array of references to B.
Here’s some pseudo code in ottoman.

var A = ottoman.model('A', { name: 'string'});
var B = ottoman.model('B', { bid: 'string'});
var C = ottoman.model('C', { a: {ref: 'A'}, bs: [{ref: 'B'}]});

I want to find all instances of C whose, and who has at least one member in the bs array of type B whose bid=value2.
I’m new to couchbase and ottoman. I can do this easily in mongo and mongoose, but I can’t wrap my head around how to do it in couchbase and/or ottoman, using either the node.js SDK or N1ql query.
Any ideas?


Hey @lichadexun,

Off the top of my head, if you do find’s for A and B to identify those items, you can do a query such as:

C.find({a: myAinstance, bs: {'$contains': myBinstance}});

Cheers, Brett


Thanks Brett.
So I would need to do 3 separate finds to achieve this, correct? Is it not possible to accomplish using 1 find or 1 N1ql query?
Does ottoman or couchbase node SDK support promises to avoid nesting of the 3 finds if it can’t be done in 1 query?



Hey lichadexun,

Currently you would need to do 3 finds in Ottoman. It is however possible that there is a solution to this in pure N1QL. You may wish to post in the N1QL forums. Additionally, unfortunately we do not currently have promises support in Ottoman, though we plan to add it soon!

Cheers, Brett