Compare Attribute

How I can compare document attributes with a hardcoded name. If it is missing in the document then show a warning.

You can compare attributes with equality if those are valued.
If the value is NULL then you need to compare with IS NULL
if the attribute is MISSING you need to compare with IS MISSING

SELECT   d.*
    FROM default d  
WHERE (d. attr1 = d.attr2 
                   OR ( d.attr1 IS MISSING && d.attr2 IS MISSING) 
                  OR (d.attr1 IS NULL AND d.attr2 IS NULL));
  
  SELECT   d.attr IS MISSING AS attrmissing
    FROM default d;

If attr is missing in the document it returns true

Suppose I have a document, There is type Customer. In customer, there is lots of entities just like username, LastName, MailId, Sex, Address, etc. So If the username and phone number are missing in entities it shows error.

N1QL will not show any error. Could you please more specific.

If you are looking documents that missing mandatory attributes. You can form query like as follows.
OBJECT_NAMES() gives attribute names of the argument object only. It doesn’t go recursively or non-objects.

SELECT d
FROM default AS d
ANY  v IN ["username","phonenumber"]  SATISFIES v  NOT IN OBJECT_NAMES(d) END

So can we write map reduce function for in that case.
I want to show missing object names in any document. object name I will pass in where condition.