Skip to content
Ray Wang edited this page Aug 12, 2019 · 4 revisions
  • TypeError: First argument needs to be a ViewQuery, SpatialQuery or N1qlQuery.

    Root Clause: You are using multiple version couchbase SDK

    Solution: Unified the couchbase SDK version.

    • Use yarn list couchbase to list all the lib who depends on couchbase

    • If you want to use couchbase==2.6.4 but the loopback-connector-couchbase5 is using 2.6.3, Update package.json as following:

      "resolutions": {
        "loopback-connector-couchbase5/**/couchbase": "^2.6.4"
      }
  • N1QL query ran out of Query Service memory

    There are serval possibilities:

    • You have a ORDER BY statement in your query

      An N1QL example:

      select * from sample where type = 'Hotel' ORDER BY city DESC
      • If you only have the type index and you have 1,000 + hotel matched records, the Query Service will fetch all matched records and sort in memory.

      • If you have type and city index, but without the DESC in create statement, the Query Service will still use a memory sort. Look at here for detail.

      • If you have type and city DESC index, but the Query Service still using wrong index (may be the type index), try to use query option to force Query Service to use specific index, an example as follows:

      const hotels = await Hotel.query({ where: {}}, { index: 'city_type_index'});
    • The index status is not ready.

    1. Check the index status at Admin Web UI or use N1QL as follows

      SELECT *  from system:indexes
    2. If the index is not at ready, Run BUILD INDEX to kick off the buliding progress.

    • You are using primary index to fulfill the query.

      1. Update the mixins options to disable primary as follows
      {
        "name": "Example",
        "base": "PersistedModel",
        "mixins": {
          "N1ql": {
            "primary": false, # Here
            "drop": false,
            "deferred": true  
          }
        },
        "indexes": {
          "status_type": {
              "keys": {
                "type": 1,
                "_type": 1,
                "status": 1,
                "createdAt": 1
            }
          },
        },
        "properties": {},
        "validations": [],
        "relations": {},
        "acls": [],
        "methods": {}
      }
      1. Drop primary index on test environment (DO NOT it at prod)
      2. find out which query (API) are using primary index,
      3. create an GSI or VIEW index to service the query.