1

I am trying to get a single document from a couchbase cluster. However, N1QL is disabled in the cluster.

I wanted to know if there is any way to get the document from the bucket without a N1QL query. I do not know the document ID's as well.

I simply need an option to get a random document(can be any document) from the entire bucket, without using the document ID or the N1QL query.

Is there any method in the JAVA SDK api that lets me do that? I am using version 2.7 however any version which does this can help.

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
  • I don't think this is really possible with N1QL or some other service (like Full Text Search or Analytics) or without creating a map/reduce index. Do you know the *format* of the document IDs? If they are just integers, you could probably make random guesses until one of them worked. Otherwise, I just don't see how you could do this. Maybe if you explained *why*, I could suggest something else? – Matthew Groves Aug 09 '21 at 16:43
  • No. We do not have integer document IDs . Cant say that for sure as well. We are trying to get the attribute names of the documents without doing a full table scan as in production that would result in a lot of documents. Since its schemaless we are trying the most efficient way to get attribute names. We know there would be loss of data as well. The DBA has said most of the clusters do not support N1QL at all. So I was asking if there is any way to do that. Thanks :D – Shraman Das Aug 09 '21 at 17:28
  • I meant *without N1QL* in my first comment, btw – Matthew Groves Aug 10 '21 at 19:19
  • I think the tool that you need is `INFER`; it's exactly meant to get a (random) sampling of documents to infer the metadata. However, this is a N1QL feature. https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/infer.html – Matthew Groves Aug 10 '21 at 19:20
  • yeah. So our couchbase clusters do not have a query node installed. That is why we are not able to do N1QL queries on the cluster. – Shraman Das Aug 11 '21 at 04:21
  • Yeah we did come across INFER. However, as you said, it is still a N1QL query. So, is there any way to do the same with SDK? Like I can list the buckets in the cluster with the `listbuckets = cluster.clusterManager().getBuckets();`. Is there any way I can do the same for inferring or pick random documents through the SDK itself? – Shraman Das Aug 11 '21 at 04:59
  • I'm not aware of anything like that without N1QL (or Analytics or FTS or a map/reduce view) – Matthew Groves Aug 11 '21 at 20:04

1 Answers1

1

You can get them via the web console. You can ask your DBA to use RBAC to give you read-only access. There are other methods that you could use as well, but they will need admin access.

Best,

deniswsrosa
  • 2,421
  • 1
  • 17
  • 25
  • 1
    Hey Thanks. But since we are planning to do a read on a lot of clusters it wont be possible to go to web consoles of each cluster. We have plenty of them. However, could you outline briefly on what methods are there with admin access? Thanks :D – Shraman Das Aug 09 '21 at 15:43
  • 1
    What are your permissions on these clusters? – deniswsrosa Aug 09 '21 at 19:19
  • 1
    I guess only read access. However do let me know the process for other access roles if possible so that I can request for those access roles. – Shraman Das Aug 11 '21 at 04:20