I have a view which filters out the data for me. I want to add a check in my search criteria => If a field does not exist in document don't consider that document.
Here is my view code, studentId may not be present in all the documents.
function (doc, meta) {
if(meta.id && meta.id.indexOf("DOCUMENT_") == 0 && doc.studentId != null) {
emit([doc.studentId, doc.studentStatus, doc.studentName], null);
}
}
Any pointers?
In your code, simply use the same syntax you used earlier in the if statement:
if(doc.studentId && meta.id && meta.id.indexOf("DOCUMENT_") == 0) ...
Note that the following
if(doc.studentId...
will return true if studentId is defined, otherwise false.