Ottoman Model - Reference Object Failing to Load Data

Hi @nraboy, attended your Developer workshop at Connect2017 and really enjoyed it, thanks for all that you and your team do.

I recently came across Ottoman and have been following your tutorial at the following link Developing an API with Node.js using Couchbase NoSQL and Ottoman . Great material, but I found a quirk and hopefully I’m missing something simple.

Here’s a sample of a snippet of the api written in this tutorial:

router.get("/:id", function(req, res) {
	PersonModel.getById(req.params.id, {load: ['comments']}, function(error, person) {
		if(error) {
			return res.status(400).send(error);			
		}
		console.log(person);
		res.send(person); 
	});
});

So my issue is that when I get a person’s info from their ID, I’m not getting all the details from the referenced document (comment). Here’s sample output that I get:

        {
            "$ref": "Comment",
            "$id": "5b7b09e8-0bd3-4cc8-a476-d91d5bc3a59d"
        }

I should be getting the detailed information from the reference document, and as you can see I am loading the comments as i should be. Even weirder is that I console logged the object (only a snippet shown below) before I res.send it and it shows that the comment details are loaded.

comments: [ OttomanModel(`Comment`, loaded, key:Comment|5b7b09e8-0bd3-4cc8-a476-d91d5bc3a59d, {
      timestamp: 2017-11-18T07:39:37.820Z,
      _id: '5b7b09e8-0bd3-4cc8-a476-d91d5bc3a59d',
      message: 'This message is a test',
    })]

So I’m not sure why the actual returned object does not contain the detailed message. I am using ottoman version 1.0.4 and couchbase version 2.4.2.

Thank you

Found a solution here, I believe it was a misalignment with Couchbase and ottoman version compatibility. I uninstalled ottoman and Couchbase, and then completely wiped my node_modules directory. Once that was cleaned up I installed Ottoman version 1.0.4. This installed the correct Couchbase version for me and it began working without any code changes.

Awesome, sorry for my late response. @brett19, any information on the version compatibility issues?

Hey @justin.laveroni, @nraboy,

You can find more information here:

Cheers, Brett

1 Like

hi, @nraboy @brett19:

  thank you  for give us great ottoman software and greate tutorial. I subscribe nraboy youtube. and I have @justin.laveroni same issue.  I write code follow nraboy youtube tutorial. and it can get and post, but when I get $ref document, I still only get the ref ID.
 this is my env: 


I install ottoman from npm i git+https://xxxxxxxxxxx.
and I test many times, even create new project three times. but still have is issue.
my code below:



when I use postman get person:

thanks!

Hey @angular,

When you fetch documents with Ottoman, it will only fetch the top-level document. In order to access the referenced documents such as the comments, you will need to call .load() on the comments array.

Chees, Brett

hi @brett19:

  thanks for your reply. I try add .load() to comments arry, but always have issue. can you tell me where can add .load() function?


best Regards