Get document by id using regullar expression

Is there a way to get a document by id using regex, or is there a way to set query startkey and endkey by regex and get the query rows ?

if regex is supported then this could change the way of storing documents and reference document keys.

No; that’s not possible with any type of index I know about. Indexes just store keys in order and let you quickly find a key by exact match.

You can do this yourself by iterating over all documents and doing a regex match on the docID. Even if we implemented this functionality, we’d be doing it the same way. It won’t scale very well, of course, so I wouldn’t recommend it if you have a large data set.

Part of working with databases is adapting to doing things in ways that they’re efficient at. There are probably other ways of doing the key lookup you want to do, that will work better.

@Alidoust @jens

I know this has been forever ago. Did you ever figure this out?

Although I have a solution, I would prefer to use the “recommended” or proper method of doing so. I have posted my question here.

No I didn’t find proper solution, But the thing is you can use N1ql to query using regex.

Right. Thank you for your reply.

In case you were still curious, I did learn you can apply regular expressions in FTS against the built-in “_id”. However, if the regex is too broad and covers too many results it will not work. I was told this is addressed in 6.5. We cannot upgrade yet, so we have to use the regex in N1QL, as you said.



I m not sure does it scale or not. My experience on a cluster with 96 GB Ram and 12 core cpus with over 60 million documents tells me it is impossible to do mass operations at scale. The purpose of regex for me was to delete batch or select batch which seems impossible.