filterToDocument :: (PersistEntity val, PersistEntityBackend val ~ DB.MongoContext) => Filter val -> DB.Document
filterToDocument f =
    case f of
      Filter field v filt -> [filterToBSON (fieldName field) v filt]
      BackendFilter mf -> mongoFilterToDoc mf
      -- The empty filter case should never occur when the user uses ||.
      -- An empty filter list will throw an exception in multiFilter
      --
      -- The alternative would be to create a query which always returns true
      -- However, I don't think an end user ever wants that.
      FilterOr fs  -> multiFilter OrDollar fs
      -- Ignore an empty filter list instead of throwing an exception.
      -- \$and is necessary in only a few cases, but it makes query construction easier
      FilterAnd [] -> []
      FilterAnd fs -> multiFilter AndDollar fs
filterToDocument :: (PersistEntity val, PersistEntityBackend val ~ DB.MongoContext) => Filter val -> DB.Document
filterToDocument f =
    case f of
      Filter field v filt -> [filterToBSON (fieldName field) v filt]
      BackendFilter mf -> mongoFilterToDoc mf
      -- The empty filter case should never occur when the user uses ||.
      -- An empty filter list will throw an exception in multiFilter
      --
      -- The alternative would be to create a query which always returns true
      -- However, I don't think an end user ever wants that.
      FilterOr fs  -> multiFilter OrDollar fs
      -- Ignore an empty filter list instead of throwing an exception.
      -- \$and is necessary in only a few cases, but it makes query construction easier
      FilterAnd [] -> []
      FilterAnd fs -> multiFilter AndDollar fs
filterToDocument f =
    case f of
      Filter field v filt -> [filterToBSON (fieldName field) v filt]
      BackendFilter mf -> mongoFilterToDoc mf
      -- The empty filter case should never occur when the user uses ||.
      -- An empty filter list will throw an exception in multiFilter
      --
      -- The alternative would be to create a query which always returns true
      -- However, I don't think an end user ever wants that.
      FilterOr fs  -> multiFilter OrDollar fs
      -- Ignore an empty filter list instead of throwing an exception.
      -- \$and is necessary in only a few cases, but it makes query construction easier
      FilterAnd [] -> []
      FilterAnd fs -> multiFilter AndDollar fs