createPrimaryIndex, createIndex fail when collectionName is provided

couchnode: 4.2.5, server: 7.2

createPrimaryIndex, createIndex fail when collectionName is provided:

creating primary index..
[InvalidArgumentError: invalid argument] {
  cause: [Error: invalid_argument (3)] {
    ctxtype: 'http',
    code: 3,
    client_context_id: '79cc354c-5e71-4b07-6088-348299ad1623',
    method: '',
    path: '',
    http_status: 0,
    http_body: '',
    last_dispatched_to: '',
    last_dispatched_from: '',
    retry_attempts: 0,
    retry_reasons: []
  context: HttpErrorContext {
    method: '',
    request_path: '',
    response_code: 0,
    response_body: ''

Hi @dixieJoy – Welcome to the Couchbase forums!

Creating a collection index from the cluster has been deprecated, but if going down this path you must specify both the scopeName and collectionName:

    const qixm = cluster.queryIndexes()
    await qixm.createPrimaryIndex('testBucket', {
        collectionName: 'testCollection',
        scopeName: 'testScope',

The preferred way to handle a collection’s indexes is to use the CollectionQueryIndexManager:

    const cluster = await couchbase.connect('couchbase://localhost', {
      username: 'Administrator',
      password: 'password',
    const bucket = cluster.bucket('testBucket')
    const collection = bucket.collection('testCollection')
    const qixm = collection.queryIndexes()

    await qixm.createPrimaryIndex()

I hope this helps.

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