The issue about ottoman index

guys, happy holiday.
When I try to use couchbase ottoman, I try to add index to the Model like this

{
	index:{
	findByName:{
		by:'title',
		type:'n1ql'
		
	},
	findByFeature:{
		by:'feature',
		type:'n1ql'
	}
	
}
} 

then, I tried to call this method at the service, like this
var Model = require('../models/test.js');

	Model.findByName(entity.title,function(err,result){
						if(err) console.log(err);
						console.log(result);
					});

but when I run this method, the program will jump to ottoman.js tell me that

 schema.store.searchIndex(
              ^

TypeError: Cannot read property 'searchIndex' of null

The reason is that in the Model I have imported, Model.schema.store=null

What is the right way to use ottoman index? Can somebody help me?

Hey @zzkkyy1000,

It looks like you need to initialize Ottoman with a storage target, see the following example:

var ottoman = require('ottoman');
var couchbase = require('couchbase');

var cluster = new couchbase.Cluster('couchbase://127.0.0.1');
var bucket = cluster.openBucket('default');
ottoman.bucket = bucket;

Cheers, Brett

1 Like

Hi Brett, I also have an index issue:

/Users/alexander/dev/proto0/node_modules/ottoman/lib/storeadapter.js:361
  var bucketMgr = this.bucket.manager();
                             ^

TypeError: Cannot read property 'manager' of undefined
    at CbStoreAdapter._ensureMrIndices (/Users/alexander/dev/proto0/node_modules/ottoman/lib/storeadapter.js:361:30)
    at CbStoreAdapter.ensureIndices (/Users/alexander/dev/proto0/node_modules/ottoman/lib/storeadapter.js:450:8)
    at _ensureAllStores (/Users/alexander/dev/proto0/node_modules/ottoman/lib/ottoman.js:846:17)
    at handler (/Users/alexander/dev/proto0/node_modules/ottoman/lib/ottoman.js:861:9)
    at handler (/Users/alexander/dev/proto0/node_modules/ottoman/lib/ottoman.js:793:7)
    at /Users/alexander/dev/proto0/node_modules/ottoman/lib/storeadapter.js:289:5
    at _combinedTickCallback (node.js:370:9)
    at process._tickCallback (node.js:401:11)
    at Function.Module.runMain (module.js:449:11)
    at startup (node.js:141:18)

Which seems to be around my usage of Ottoman ‘ensureIndices’:

ottoman.ensureIndices(function(err) {
  if (err) return console.error(err);
});

I’m going nuts here, whats this error about, I’m following the tutorial here: https://github.com/couchbaselabs/comply/ to no avail…

Hey @alexander ,

It looks like you have failed to set the ottoman.bucket property with an appropriate bucket object reference to use. This is causing the ensureIndices to attempt to use a null object with its method calls.

Cheers, Brett

Hi @brett19 i’ve the following:

module.exports.bucket = (new couchbase.Cluster('couchbase://localhost')).openBucket('default');
ottoman.bucket = module.exports.bucket; 

but no dice…

I am getting the same error.

schema.store.createIndex(modelIndex.type, schema.namePath(),
^

TypeError: Cannot read property ‘createIndex’ of null
at Ottoman._ensureModelIndices (/Users/Raja/server/node_modules/ottoman/lib/ottoman.js:900:17)
at _ensureAllModels (/Users/Raja/server/node_modules/ottoman/lib/ottoman.js:966:12)
at Ottoman.ensureIndices (/Users/Raja/server/node_modules/ottoman/lib/ottoman.js:969:3)
at Bucket. (/Users/Raja/server/schema/cb/CouchBaseAdapter.js:57:25)
at emitNone (events.js:110:20)
at Bucket.emit (events.js:207:7)
at Bucket. (/Users/Raja/server/node_modules/couchbase/lib/bucket.js:177:10)

myCluster = new couchbase.Cluster(‘couchbase://HOSTNAME’);
myBucket = myCluster.openBucket(‘DEFAULT’);
ottoman.store = new ottoman.CbStoreAdapter(myBucket, couchbase);
ottoman.ensureIndices(function () { });

“dependencies”: {
“body-parser”: “^1.17.2”,
“connect-timeout”: “^1.8.0”,
“couchbase”: “^2.3.5”,
“express”: “^4.15.3”,
“https”: “^1.0.0”,
“ottoman”: “^1.0.4”,
},