3

I am using the python-cloudant library, trying to do a query:

import cloudant

my_database = client['database']

query = cloudant.query.Query(my_database,selector={'selector': {'$gt': 0}},fields=['doi'])
for doc in query(limit=100, skip=100)['docs']:
    print doc

This gives me an error: HTTPError: 400 Client Error: Bad Request for url: https://myurl.com/mydatabase/_find

With this error when I try loading the page in a browser: {"error":"method_not_allowed","reason":"Only POST allowed"}

What am I missing here?

pynewb
  • 198
  • 1
  • 11

1 Answers1

6

Unless you have an index on the field named selector then this query won't work.

So assuming that you meant to use the primary index which is on the _id field then if you change selector={'selector': {'$gt': 0}} to selector={'_id': {'$gt': 0}} this query should work.

As in:

import cloudant

client = cloudant.Cloudant(USER, PWD, account=ACCOUNT)
client.connect()

my_database = client['database']

query = cloudant.query.Query(my_database,selector={'_id': {'$gt': 0}},fields=['doi'])
for doc in query(limit=100, skip=100)['docs']:
    print doc
Panda
  • 1,231
  • 18
  • 27
alfinkel24
  • 551
  • 5
  • 13