multiFilter multi filters =
  case (multi, filter (not . null) (map filterToDocument filters)) of
    -- a $or must have at least 2 items
    (OrDollar,  []) -> orError
    (AndDollar, []) -> []
    (OrDollar,    _:[]) -> orError
    (AndDollar, doc:[]) -> doc
    (_, doc) -> [toMultiOp multi DB.:= DB.Array (map DB.Doc doc)]
  where
    orError = throw $ PersistMongoDBError $
        "An empty list of filters was given to one side of ||."
multiFilter multi filters =
  case (multi, filter (not . null) (map filterToDocument filters)) of
    -- a $or must have at least 2 items
    (OrDollar,  []) -> orError
    (AndDollar, []) -> []
    (OrDollar,    _:[]) -> orError
    (AndDollar, doc:[]) -> doc
    (_, doc) -> [toMultiOp multi DB.:= DB.Array (map DB.Doc doc)]
  where
    orError = throw $ PersistMongoDBError $
        "An empty list of filters was given to one side of ||."
multiFilter multi filters =
  case (multi, filter (not . null) (map filterToDocument filters)) of
    -- a $or must have at least 2 items
    (OrDollar,  []) -> orError
    (AndDollar, []) -> []
    (OrDollar,    _:[]) -> orError
    (AndDollar, doc:[]) -> doc
    (_, doc) -> [toMultiOp multi DB.:= DB.Array (map DB.Doc doc)]
  where
    orError = throw $ PersistMongoDBError $
        "An empty list of filters was given to one side of ||."