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..
"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]
コメントを追加