couchdb-python icon indicating copy to clipboard operation
couchdb-python copied to clipboard

Support mango queries

Open henridwyer opened this issue 9 years ago • 10 comments

CouchDB 2 has a new way to query the database without using views:

  • https://blog.couchdb.org/2016/08/03/feature-mango-query/
  • https://github.com/cloudant/mango

Perhaps this could be implemented as two new database functions:

  • mango_query
  • mango_index

henridwyer avatar Aug 13 '16 23:08 henridwyer

Hey, thanks for the notice. I haven't installed CouchDB 2 yet, but will likely do so soon after release. Still, I'm not sure adding APIs for Mango will be a high priority for me, personally, so it would be great if you're able to contribute some code towards this goal.

djc avatar Aug 14 '16 19:08 djc

Just thought I'd chime in that without some mango support, there will be no way to perform a query without creating a view, as they've removed temporary views in favor of this new json-based query system.

adrian-the-git avatar Sep 29 '16 20:09 adrian-the-git

I'm new to CouchDB and this project but I'm looking at trying to add these new functions mango_query and mango_index. If I have any success I'll submit a pull request.

danballance avatar Nov 02 '16 14:11 danballance

A Mango query is just a POST request to /:db/_find containing some JSON in the body, so this shouldn't be hard to make, right?

ghost avatar Feb 28 '17 08:02 ghost

Honestly, this was really dead simple to monkeypatch:

_, _, data = db.resource.post_json('_find', body={"selector" : query}, headers = {'Content-Type': 'application/json'}) return data["docs"]

Almost nearly a one-liner. Anybody wanna make a PR?

mraygalaxy avatar Jun 25 '17 06:06 mraygalaxy

Maybe like in django: For example:

data1 = db.find(field__eq='A', limit=50)
data2 = db.find(Q(field__eq='A')
                & (Q(field1__subfield1__in=['lama', 'amal'])
                    | Q(field2__subfield2__regex ="foo")), limit=40, fields=['field1', 'field2'])

I have implementation of this. If it is acceptable, I can provide my implementation. Q obj - https://github.com/pirr/alt_couch/blob/c690771f729c38ac39041d4fea981b44623a0748/_libs/vb/couch.py#L14 find method - https://github.com/pirr/alt_couch/blob/c690771f729c38ac39041d4fea981b44623a0748/_libs/vb/couch.py#L222 Sorry for my terrible english.

pirr avatar Sep 25 '17 14:09 pirr

I would like to add an implementation to CouchDB-Python. If you can provide one that fits into the library and has comments in English, I could probably review it.

djc avatar Sep 26 '17 07:09 djc

I added filter method (mango query) with comments: https://github.com/pirr/couchdb-python/commit/6f051bcd4879955610d6d2c182b53f09266022e7

pirr avatar Sep 27 '17 08:09 pirr

Looks pretty good, do you want to do a pull request for this?

djc avatar Sep 27 '17 09:09 djc

https://github.com/djc/couchdb-python/pull/324 this is my first pool reguest. If there are comments, please, I will correct

pirr avatar Sep 27 '17 11:09 pirr