How do I make a query in cloudant-python selecting an specific field?

255 Views Asked by At

I'm trying to make a query that selects only one of the fields/attributes. The query should result in something like an array of a nameField or a numberField, or even a single variable, what I want is to separate the values so I can manipulate it in the app

I already tried using "query = cloudant.query.Query(myDatabaseDemo, fields=['nameField'])" but the result when I print query is just "fields=['nameField']".

from cloudant.result import Result, ResultByKey

...

client = Cloudant(serviceUsername, servicePassword, url=serviceURL)
myDatabaseDemo = client.create_database(databaseName)

...

result_collection = Result(myDatabaseDemo.all_docs, include_docs=True)
print ("document:\n{0}\n".format(result_collection[0]))

The actual code results in a set of values, like a json document

1

There are 1 best solutions below

0
bessbd On

Have you tried using Cloudant query? It allows you to specify fields (list) – A list of fields to be returned by the query.