Document not found Ottomann

I have tried Ottomann but I get document not found error, why ?

const ottoman = new Ottoman({scopeName: 'sf_scope'});

await ottoman.connect({
  connectionString: 'couchbases://cbxxxxcmxxxx',
  bucketName: 'sf_bucket',
  username: 'xxxx',
  password: 'xxxx'
});

await ottoman.start();

const ProductsSchema = new Schema({
  click: String
});

const Products = ottoman.model('products', ProductsSchema);

app.get('/', async(req, res) => {
  try {
    console.time("concatenation");
    
    const products = await Products.findById('product1')

    console.log(products);
    
    console.timeEnd("concatenation");

    res.send('hello');
  } catch(e) {
    console.log(e);
    res.send(e);
  }
})

Error:

[DocumentNotFoundError: document not found] { 
  cause: [Error: document_not_found (101)] {  
    ctxtype: 'key_value',
    code: 101,
    id: 'products::product1',
    opaque: 12,
    cas: Cas<0>,
    status_code: 1,
    enhanced_error_info: undefined,
    last_dispatched_to: '192.168.0.20:56666', 
    last_dispatched_from: '3.249.44.37:11207',
    retry_attempts: 0,
    retry_reasons: []
  },

Well, in the error message it says : id: ‘products::product1’
And in the document it shows “id”:“product1”

So you’ll need to refer to the Ottoman documention to find out what ottoman uses for the id.

Ok - the first example shows user.save(). But I don’t see product.save() in your code. So it looks like you are inserting a ‘product1’ document outside of Ottoman. And when you try to read it inside of Ottoman, it was not saved with the id that Ottoman would use.

it is there I created on the shell

You created it in the shell with the wrong id.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.