سؤال

Somethings wrong with my couchdb complex query processing.

I have a map function which emits complex key consisted of 6 params like this:

emit([doc.profileId,  doc.beamId, doc.name, doc.beambeanchId, "true", attachName], {beamdocId:doc._id, attachName:attachName})

my query parameters (coffescript) is like this:

params =
startkey:[ profileId, beamId, namePrefix, beambeanchId, hasAttach, attachNamePrefix]
endkey:[
  profileId or "\ufff0",
  beamId or "\ufff0",
  namePrefixEnd or "\ufff0",
  beambeanchId or "\ufff0",
  hasAttachEnd,
  attachNamePrefixEnd or "\ufff0"]

The problem is that only two first are working properly, but the rest is not filtering at all. For instance when I set namePrefixEnd to a value not null it's not reducing my result.

I tried that with keys emmited as objects and arrays. Same story, only first two are working. The third is ignored. When I change order for instance beamId with namePrefixEnd still only the first two are working properly.

Any ideas what's wrong? Are there any limits on number of parameters in couchdb complex keys?

I'm using nano library to get access the data and db.view function.

هل كانت مفيدة؟

المحلول

Ok. I found answer by myself. In general the structure of the key in startkey/endkey must exact match the emited keys.

To solve my case I need to emit all possible combination of the fields I'll be looking for later.

For instance:

emit([doc.profileId,  doc.beamId, doc.name, doc.beambeanchId, "true", attachName],
     {beamdocId:doc._id, attachName:attachName})
emit([doc.profileId,  doc.name, doc.beambeanchId, "true", attachName],
     {beamdocId:doc._id, attachName:attachName})
emit([doc.profileId,  doc.name, doc.beambeanchId, "true", attachName],
     {beamdocId:doc._id, attachName:attachName})
emit([doc.profileId,  doc.beambeanchId, "true", attachName],
     {beamdocId:doc._id, attachName:attachName})
emit([doc.profileId, attachName],
     {beamdocId:doc._id, attachName:attachName})

etc. Now I can find what I need. Of course to make it bullet proof it's better to use object keys instead array, otherwise value might mixed up.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top