Gracefully handle missing document reference when running in nodejs