added '$exists' condition for queries