I was introduced to the concepts of gradient $\nabla f$, curl $\nabla \times F$ and divergence $\nabla \cdot F$ in an introductory course on calculus during my undergraduate studies. There I learnt that for any scalar function $f$ on $\mathbb{R}^2$ or $\mathbb{R}^3$, we have $\nabla \times (\nabla f) = 0$. Moreover, we saw the following standard example of a vector field $F$ on an open subset of $\mathbb{R}^2$ such that $\nabla \times F = 0$ but for which $F \neq \nabla f$ for any scalar function $f$, namely,
$$
F(x, y) = \left( \frac{-y}{x^2 + y^2}, \frac{x}{x^2 + y^2} \right)
$$
for every $(x, y) \in \mathbb{R}^2 \setminus \\{ (0,0) \\}$.
Analogously, it seems to me, we also showed that for every vector field $F$ on $\mathbb{R}^2$ or $\mathbb{R}^3$, we have $\nabla \cdot (\nabla \times F) = 0$. However, we did not consider the converse: if $F$ is a vector field on some subset of $\mathbb{R}^2$ or $\mathbb{R}^3$ such that $\nabla \cdot F = 0$, is it true that $F = \nabla \times G$ for some vector field $G$?
My *guess* is that this is not true, just as the analogous earlier question regarding the curl and the gradient had a negative answer. However, I'm not able to come up with any counterexample. I understand that (in the $\mathbb{R}^2$ case) I'm interested in finding a vector field $G(x, y) = G_1(x, y) \hat{\iota} + G_2(x, y) \hat{\jmath}$ such that
$$
\frac{\partial G_2}{\partial x} - \frac{\partial G_1}{\partial y} = F_3(x, y),
$$
where $F = F_3(x, y) \hat{k}$ is the vector field I'm starting out with.
This reminds me of an exact differential equation, but I admit I'm not familiar enough with the concept to be able to proceed further.
More generally, I would like to know whether we can put precise conditions on when a divergence-free vector field is the curl of some vector field. Like in the earlier case, I *expect* that the geometry of space should play an important role: there, asking that the domain be simply connected was a sufficient condition to guarantee the existence of the function $f$, so perhaps something similar will happen here as well?