[MOD] XQuery: generalized handling of external query resources;
      can also be used to close MongoDB and other connections