triniwiz / nativescript-plugins

Apache License 2.0
80 stars 50 forks source link

[couchbase] does like operator works? #122

Closed abdallahkadour closed 2 years ago

abdallahkadour commented 2 years ago

I am trying to execute a query against the database using the like operator to select streets. My code:

const query = this.database.query({
      select: ['name'],
      from: 'streets'-db,
      where: [
        { property: 'doc.name', comparison: 'like', value: 'Forest' }
      ],
      order: [{ property: 'doc.name', direction: 'desc' }]
    })

I have several streets which its names start with Forest but the result is always empty. If I add the property logical: QueryLogicalOperator.AND to the where clause, I got all documents from the db. Do I miss something?

abdallahkadour commented 2 years ago

Solved by passing lowercase values:

const inputQuery = '%' + text.toLowerCase() + '%'
    const query = this.database.query({
      select: ['name'],
      from:'streets-db,
      where: [
        { property: 'doc.name', comparison: 'like', value: inputQuery }
      ],
      order: [{ property: 'doc.name', direction: 'desc' }]
    })