View not working as expected (nested document)

#1

I have a document with a nested document; here is a snippet:

   "gender": "M",
   "flags_blacklist": "",
   "ids": [
       {
           "expires": "02-JUN-2015",
           "type": "1",
           "id": "134453232443"
       }
   ],
   "maritial_status": "M",
   "dependents": "",

I would like to write a view to filter those documents that have any id of type “1”, here is my attempt:

function (doc, meta) {
  if (doc.ids) {
    for (var x = 0; x < len(doc.ids); x++) {
      if (doc.ids[x].type == "1") {
      emit(doc.cif, doc.ids);
      }
    }
  }
}

cif is a key I would like to be used.

This view does not filter any documents; even though the sample random document fits the criteria; any idea what I am doing wrong here?

#2

Nevermind, I found the answer … .which is … stop trying to write Python in Javascript.

#3

I did answer this on IRC but you just logged off before I hit send :frowning:

In case anyone is wonder what the problem is , this line in the view is wrong, len() is not a method in Javascript:

for (var x = 0; x < len(doc.ids); x++) {

It should be:

for (var x = 0; x < doc.ids.length; x++) {