node-ottoman icon indicating copy to clipboard operation
node-ottoman copied to clipboard

Getting Started sample code does not work

Open thejcfactor opened this issue 3 years ago • 2 comments

If I try to run the sample code provided in the getting started section of the docs (also in the README).

const { connect, model, start, close } = require('ottoman');

const main = async () => {
  await connect("couchbase://localhost/travel-sample@admin:password");

  const User = model('User', { name: String });

  const user = new User({ name: 'Jane Doe' });

  await start();

  await user.save();
  console.log('Nice Job!');

  await close();
}

main();

I see the following error:

TypeError: Cannot read properties of undefined (reading 'collections')
    at Ottoman.get collectionManager [as collectionManager] (../node/node-ottoman/lib/ottoman/ottoman.js:173:28)
    at Ottoman.<anonymous> (../node/node-ottoman/lib/ottoman/ottoman.js:389:165)
    at Generator.next (<anonymous>)
    at ../node/node-ottoman/lib/ottoman/ottoman.js:27:71
    at new Promise (<anonymous>)
    at __awaiter (../node/node-ottoman/lib/ottoman/ottoman.js:23:12)
    at Ottoman.ensureCollections (../node/node-ottoman/lib/ottoman/ottoman.js:367:16)
    at Ottoman.<anonymous> (../node/node-ottoman/lib/ottoman/ottoman.js:444:24)
    at Generator.next (<anonymous>)
    at ../node/node-ottoman/lib/ottoman/ottoman.js:27:71

However, running the sample code modeled from the couchbase docs, I do not seem to have any problems.

const { Ottoman, Schema, SearchConsistency } = require('ottoman');
const ottoman = new Ottoman();

const main = async () => {
  var connection = await ottoman.connect("couchbase://localhost/travel-sample@Administrator:password");

  const User = connection.model('User', { name: String });

  const user = new User({ name: 'Jane Doe' });

  await connection.start();

  await user.save();
  console.log('Nice Job!');

  await ottoman.close();
}

main();

thejcfactor avatar Jul 19 '22 17:07 thejcfactor

hi @thejcfactor

I already create a PR for this issue https://github.com/couchbaselabs/node-ottoman/pull/669 will be fixed in the next version.

gsi-alejandro avatar Jul 19 '22 18:07 gsi-alejandro

@gsi-alejandro @thejcfactor is this worth updating on the ottoman.js docs site so its in sync with the couchbase docs page?

ejscribner avatar Aug 05 '22 17:08 ejscribner