Multiple Emit in View


#1

During the call to the javascript to build a view function, there is generally a single emit( ). Can their be more than 1 emit on a function?

function (doc, meta)
{
if (doc.testid__ == ‘php’)
{
emit(meta.id, NULL);
}
}

Multiple Emits:

function (doc, meta)
{
if (!(doc.type ))
{
return;
}
if (doc.type != ‘kids’)
{
return ;
}

//Multiple index building emits so that both kds will locate this document.
emit(doc.kids[0].name, NULL);
emit(doc.kids[1].name, NULL);

}


#2

@md1 yes, you can have more than one emit in a single map function. Every time you call emit it will end up in the index.

Even one of the sample views for beer-sample has it:

function (doc, meta) {
  if (doc.country, doc.state, doc.city) {
    emit([doc.country, doc.state, doc.city], 1);
  } else if (doc.country, doc.state) {
    emit([doc.country, doc.state], 1);
  } else if (doc.country) {
    emit([doc.country], 1);
  }
}