ropensci / sofa

Easy R interface to CouchDB
https://docs.ropensci.org/sofa/
33 stars 17 forks source link

db_query with a single field specification does not work #63

Closed ghost closed 6 years ago

ghost commented 6 years ago

If I just want to pull a single field from all documents matching a query, there currently does not seem to be a working approach.

db_query(myConn, 'mydb', selector = list(`_id` = list(`$gt` = NULL)), fields = '_id', limit = 2)
Error: (400) - Fields must be an array of strings, not: <<95,105,100>>

db_query(myConn, 'mydb', selector = list(`_id` = list(`$gt` = NULL)), fields = c('_id'), limit = 2)
Error: (400) - Fields must be an array of strings, not: <<95,105,100>>

Whereas, this works:

db_query(myConn, 'mydb', selector = list(`_id` = list(`$gt` = NULL)), fields = c('_id', '_rev'), limit = 2)

Of course, the workaround is to provide some random additional field, retrieve both fields from Cloudant, write an lapply function to then dump the random additional field from the output. While this is a workaround for now, it will be nice for the code to work as expected.

BTW - single field works just fine in Python with the corresponding module. :)

sckott commented 6 years ago

thanks for the report @tumulurig3 , will look into this

sckott commented 6 years ago

@tumulurig3 try again after reinstalling devtools::install_github("ropensci/sofa")

ghost commented 6 years ago

Works perfectly! Thank you.