Query for ANY value in complex key (AKA wildcard)

Alex Green

I went through docs and SO questions but didn't find any clear answer for my particular case.

Having this complex (emitting array) key map func in view

function(doc) {
    if (doc.userFirstName && doc.userLastName && doc.userGender && doc.homeCountry && doc.homeCity) {
      emit([
        doc.userFirstName,
        doc.userMiddleName,
        doc.userLastName,            
      ], null)
    }

I want to query it with values some of which are empty - so query could accept ANY values from the key, i.e.

userFirstName = *anyvalue*
userMiddleName = *anyvalue*
userLastName = "Mozart"

If it's possible - what should my startKey= and endKey= request parameters look like? I tried

startkey=[{},{},"Mozart"]&endkey=[{},{},"Mozart"]

but with no avail - got no rows..

Alex Green

"Any_value" wildcard in couchdb query isn't possible (yet, question to devs - why not?), so the only way to perform multy-dimensional lookup with empty (=accept_any) values is to maintain indexes for all possible combinations of non-empty search values. I ended up with this _design doc:

let ddoc = {
      '_id': '_design/search',
      'views': {
        'firstOnly': {'map': firstOnly},
        'middleOnly': {'map': middleOnly},
        'lastOnly': {'map': lastOnly},
        'firstLast': {'map': firstLast},
        'firstMiddle': {'map': firstMiddle},
        'middleLast': {'map': middleLast}
      }
    };

where (i.e. for known middleName and lastName) map function looks like:

const middleLast =
  `function(doc) {
    if (doc.userMiddleName && doc.userLastName) {
      emit([
        doc.userMiddleName,
        doc.userLastName,
      ], null)
    }
  }`;

Then can I query corresponding view depending on dataset known.

So six complex key indexes instead of one. Quite heavy (in case of millions of records), but, unfortunately, the only possible solution.

Thanks to all responders, your help is unvaluable.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

dictionary of key and list - remove key if any value in list is none

分類Dev

Append key value pairs to query string

分類Dev

sed: extracting value of a key-value pair in a URL query string

分類Dev

Multi Dimensional array value print without any key

分類Dev

Get the value for a specific key from any type in terraform

分類Dev

Extract any value from hashmap (one for each key)

分類Dev

Is there any way to access individual values of a map of <key, value> pairs in karate if we do not know the value of key?

分類Dev

Complex Ebean Query

分類Dev

LIMIT not working on complex query

分類Dev

Stop LINQ Query if Default Value is Returned at Any Point

分類Dev

Parse query containedIn doesn't return any value

分類Dev

Set int var value as wildcard

分類Dev

Iterate through a mongocxx query to get each key and value

分類Dev

How to sort DynamoDB query result without specifying range key value

分類Dev

Python: dict within dict, wildcard first key

分類Dev

What is a complex mapping key in YAML?

分類Dev

Creating a search query with wildcard in SQL2

分類Dev

Convert a complex SQL query to SQLAlchemy

分類Dev

Django Complex Query: combined output

分類Dev

How to achieve this complex query with Eloquent?

分類Dev

Complex mysql query with conditional results

分類Dev

Complex SQL query on javascript object

分類Dev

Any shortcut to get ratio by multiple rows/columns key value matching in python?

分類Dev

How do I get the full value(including any additional tags) from .text of an XML key / Value using Javascript

分類Dev

Rails 5 complex query with multiple sub queries

分類Dev

mongodb complex query between two collections

分類Dev

Complex JOIN SQL query in Laravel 5

分類Dev

Complex JOIN SQL query in Laravel 5

分類Dev

web2py DAL complex query

Related 関連記事

  1. 1

    dictionary of key and list - remove key if any value in list is none

  2. 2

    Append key value pairs to query string

  3. 3

    sed: extracting value of a key-value pair in a URL query string

  4. 4

    Multi Dimensional array value print without any key

  5. 5

    Get the value for a specific key from any type in terraform

  6. 6

    Extract any value from hashmap (one for each key)

  7. 7

    Is there any way to access individual values of a map of <key, value> pairs in karate if we do not know the value of key?

  8. 8

    Complex Ebean Query

  9. 9

    LIMIT not working on complex query

  10. 10

    Stop LINQ Query if Default Value is Returned at Any Point

  11. 11

    Parse query containedIn doesn't return any value

  12. 12

    Set int var value as wildcard

  13. 13

    Iterate through a mongocxx query to get each key and value

  14. 14

    How to sort DynamoDB query result without specifying range key value

  15. 15

    Python: dict within dict, wildcard first key

  16. 16

    What is a complex mapping key in YAML?

  17. 17

    Creating a search query with wildcard in SQL2

  18. 18

    Convert a complex SQL query to SQLAlchemy

  19. 19

    Django Complex Query: combined output

  20. 20

    How to achieve this complex query with Eloquent?

  21. 21

    Complex mysql query with conditional results

  22. 22

    Complex SQL query on javascript object

  23. 23

    Any shortcut to get ratio by multiple rows/columns key value matching in python?

  24. 24

    How do I get the full value(including any additional tags) from .text of an XML key / Value using Javascript

  25. 25

    Rails 5 complex query with multiple sub queries

  26. 26

    mongodb complex query between two collections

  27. 27

    Complex JOIN SQL query in Laravel 5

  28. 28

    Complex JOIN SQL query in Laravel 5

  29. 29

    web2py DAL complex query

ホットタグ

アーカイブ