Get details for referenced documents

Hi Team,

I am using ottoman for communicating with couchbase.

I want to get details of the referenced document from the response of the current document.

I have a document for groups and its structure is as below:

"_type": “groups”,
“group_members”: [
"_type": “subscribers”,
"$ref": “7d4ab00e-26b8-45ae-93b9-9a4c1e29e584”
"_type": “subscribers”,
"$ref": “10ce32d6-252e-41d4-b63a-cf240740eb27”
"_type": “subscribers”,
"$ref": “f98aaaa6-dae3-4788-8983-cdeb1df26b25”
“created_on”: “2016-04-16T11:58:06.976Z”,
"_id": “be0790db-ebf4-4ebf-9e6e-d3ac5590576e”,
“group_name”: “Test Group”,
“created_by”: {
"_type": “users”,
"$ref": “f13368cf-7bb7-438b-b5e8-6638b9fa7273”

Now, when I query this document, I get the response as below:

OttomanModel(groups, loaded, key:groups|be0790db-ebf4-4ebf-9e6e-d3ac5590576e, {
group_members: [ OttomanModel(subscribers, unloaded, key:subscribers|7d4ab00e-26b8-45ae-93b9-9a4c1e29e584, {}),
OttomanModel(subscribers, unloaded, key:subscribers|10ce32d6-252e-41d4-b63a-cf240740eb27, {}),
OttomanModel(subscribers, unloaded, key:subscribers|f98aaaa6-dae3-4788-8983-cdeb1df26b25, {}) ],
created_on: Sat Apr 16 2016 11:58:06 GMT+0000 (UTC),
_id: ‘be0790db-ebf4-4ebf-9e6e-d3ac5590576e’,
group_name: ‘Test Group’,
created_by: OttomanModel(users, unloaded, key:users|f13368cf-7bb7-438b-b5e8-6638b9fa7273, {}),

From this response, I need to get details for subscribers like name, email etc. whose keys are present in the group members array above.

How can this be achieved using ottoman?

Hey @ajinkyaudgirkar,

You should be able to query your groups like so:

GroupModel.find({}, {load:'group_members'}, function(err, groups) {
  // group_members will be populated here...

Cheers, Brett