Preheat the oven to 450°F (230°C). Crack each egg into a small dish and let them come to room temperature while you prepare the sauce.
Heat the olive oil in an oven-safe skillet over medium heat. Add the finely diced onion and sauté 1–2 minutes until softened.
Add the canned diced green chiles to the pan and cook 1–2 minutes more.
Stir in the ground cumin and ground ancho chile pepper and cook another 1–2 minutes to toast the spices.
Add the canned diced tomatoes and the rinsed, drained black beans (if using). Bring the mixture to a simmer and cook about 8–10 minutes, stirring occasionally, until the sauce has reduced and you can see the bottom of the pan when scraped.
Spoon a layer of the tomato mixture into the bottom of three individual gratin dishes (or leave it in the skillet/casserole). Use the back of the spoon to make six shallow wells for the eggs.
Carefully slip two eggs into each gratin dish, or add all six eggs into the skillet/casserole, placing them into the wells in the sauce.
Bake in the preheated oven 8–9 minutes, or until the egg whites are beginning to set but the yolks are still soft; a larger casserole may need slightly longer.
Remove the dish from the oven and switch the oven to broil. Sprinkle the grated Mexican blend cheese evenly over the eggs.
Place the dish(es) under the broiler about 1–2 minutes just until the cheese melts and is lightly browned—watch carefully to avoid overcooking.
Remove from the oven while yolks are still soft. Garnish with sliced green onion or chopped cilantro if desired and serve hot.