Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

method for mango query #324

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

method for mango query #324

wants to merge 7 commits into from

Conversation

pirr
Copy link

@pirr pirr commented Sep 27, 2017

I suggest implementation for mango query (only CouchDB 2) http://docs.couchdb.org/en/2.1.0/api/database/find.html.

I used django's filter implementation.
data = db.filter(field__subfield1__...__mango_operator = value)

data = db.filter(Q(field1__subfield1__...__mango_operator = value)
                          | Q(field2__subfield1__...__mango_operator = value)
                          & Q(field3__subfield1__...__mango_operator = value))

Work:

  1. Combination operators: http://docs.couchdb.org/en/2.1.0/api/database/find.html#combination-operators, except: $elemMatch, $allMatch.
  2. Condition operators http://docs.couchdb.org/en/2.1.0/api/database/find.html#condition-operators,
    not tested types: Object, Array-$size, Miscellaneous - $mod.
  3. Sort, limit, fields and other request json object but need test http://docs.couchdb.org/en/2.1.0/api/database/find.html#db-find

I will work on update. In first I would add Array operators - $elemMatch, $allMatch.

@pirr pirr mentioned this pull request Sep 27, 2017
@pirr
Copy link
Author

pirr commented Oct 3, 2017

I added support for $elemMatch, maybe $allMatch (not tested).
aaf0395

feats: [{subfeat: 1, ...}, {subfeat: 2, ...}]
db.filter(feats_L_elemMatch__subfeat__eq = 1)

feats: ['FOO', 'BAR']
db.filter(feats_L_elemMatch__regex = '(?i)fo')

"_L_" - define "feats" field as list
"elemMatch__subfeat__eq" - selector on "subfeat" field

This can be bad implementation. I will be glad to suggestions.

@djc
Copy link
Owner

djc commented Oct 5, 2017

As you can see here, there are some test failures caused by this PR. Can you look at those and make sure they no longer fail?

@pirr
Copy link
Author

pirr commented Oct 5, 2017

I fixed doctest. But travis log error:

couchdb.http.ServerError: (400, ('bad_request', 'Referer header required.'))

I not get this error in local test log.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants