Support mango queries
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
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.
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.
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.
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?
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?
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.
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.
I added filter method (mango query) with comments: https://github.com/pirr/couchdb-python/commit/6f051bcd4879955610d6d2c182b53f09266022e7
Looks pretty good, do you want to do a pull request for this?
https://github.com/djc/couchdb-python/pull/324 this is my first pool reguest. If there are comments, please, I will correct