Delete couchbase forged entry with regex key

I have a requirement in which I need to delete an entry from a couchbase bucket. I am using the CouchbaseCient removal method from my Java application to which I pass the key. But in one specific case, I do not have the whole key name, but part of it. So I thought that there would be a method that takes a match, but I could not find it. Below is the actual key that is stored in the bucket

  123_xyz_havefun

and part of the key that I have is xyz. I am not sure that this can be done. Can someone help.

+4
source share
3 answers

DELETE Couchbase , . - . , Couchbase Views APPEND. , xyz ,

+6

, , , .

:  - Couchbase  -  - .

, , , , , .

, , , , SQL-, "DELETE *" , - "match%".

, CouchBase N1QL ( nickle). JavaScript ( ), , python.

: b, META (b).id LIKE "%"

layer_name_prefix = cb_layer_key + "|" + "%"
query = ""
try:
    query = N1QLQuery('DELETE from `test-feature` b where META(b).id LIKE $1', layer_name_prefix)
    cb.n1ql_query(query).execute()
except CouchbaseError, e:
    logger.exception(e)

: , "" / , "parent_id".

DELETE, type = 'Feature' parent_id = 8;

, , , CouchBase , / ( ).

+2

, , , .

An ( ) :

function(doc, meta) {
  if (meta.id.match(/_xyz_/)) {
    emit(meta.id, null);
  }
}

, . .

function(doc, meta) {
  var match = meta.id.match(/^.*_(...)_.*$/);
  if (match) {
    emit(match[1], null);
  }
}

In your case, this will produce a key xyz(or the corresponding component from each key) for each document. Then you can use startkeyand endkeyto limit based on your criteria.

Finally, there are many options from the information search space for creating text indexes that can be applied here. I will link to this permuterm index document to get you started.

0
source

Source: https://habr.com/ru/post/1524702/


All Articles